Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPP_Demo memory dump #31

Closed
tyqdd2008 opened this issue Oct 31, 2022 · 0 comments
Closed

CPP_Demo memory dump #31

tyqdd2008 opened this issue Oct 31, 2022 · 0 comments

Comments

@tyqdd2008
Copy link

In CPP_Demo project, there is something problem which could cause memory dump as below:

 // Create 10 different SigGen signal generator task instances with calibration parameters and dynamic addressing
// The constructor of SigGen will create an instance amd an associated XCP event
SigGen* sigGen[10];
for (int i = 0; i <= 9; i++) {
    std::string* s = new std::string("SigGen"); s->append(std::to_string(i+1));
    sigGen[i] = new SigGen((char*)s->c_str(), 2000, 100.0-i*5, 0.0, i*M_PI/15.0, 2.0);
}

// Create A2L description for class SigGen, use any instance to do this, function cant be static
sigGen[0]->a2lCreateTypedef();


// Create virtual instances of pMinSigGen and pMaxSigGen 
minSigGenEvent = new XcpDynObject("pMinSigGen", SigGen);
maxSigGenEvent = new XcpDynObject("pMaxSigGen", SigGen);

Create virtual instances of pMinSigGen and pMaxSigGen could be done before Create 10 different SigGen signal generator task instances.

It should be like this

// Create virtual instances of pMinSigGen and pMaxSigGen 
minSigGenEvent = new XcpDynObject("pMinSigGen", SigGen);
maxSigGenEvent = new XcpDynObject("pMaxSigGen", SigGen);

// Create 10 different SigGen signal generator task instances with calibration parameters and dynamic addressing
// The constructor of SigGen will create an instance amd an associated XCP event
SigGen* sigGen[10];
for (int i = 0; i <= 9; i++) {
    std::string* s = new std::string("SigGen"); s->append(std::to_string(i+1));
    sigGen[i] = new SigGen((char*)s->c_str(), 2000, 100.0-i*5, 0.0, i*M_PI/15.0, 2.0);
}

// Create A2L description for class SigGen, use any instance to do this, function cant be static
sigGen[0]->a2lCreateTypedef();

The SigGen class will generate a thread which could use minSigGenEvent/maxSigGenEvent(points to objects). In some situations minSigGenEvent/maxSigGenEvent will be initialized before the threads use minSigGenEvent/maxSigGenEvent . But it not always works and cause the memory dump.
Wish it helps.

@RainerZ RainerZ closed this as completed May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants