AnsweredAssumed Answered

STM32 & Keil memory management in C++

Question asked by longchair.m on Sep 27, 2012
Latest reply on Sep 27, 2012 by fm
Hello,

I am using Keil and I have started to try using C++. That seems to work okay except that i ran into some strange behaviour for which I have no explanation.

Lets say that I have 4 different classes C1, C2, C3 and C4. None of these classes have a lot of data as member data (maybe 10 x u 32 for each).

In the main loop I need to instanciate one of each of these classes. and for two ways which should give the same results I have two different behaviours :

Situation 1, This situation works flawlessly :

C1 myC1;
C2 myC2;
C3 myC3;
C4 myC4;

void main(void)
{
    C1.dosomething();
....
}


Situation 2 : This situation is hanging up the running.

void main(void)
{
     C1 *pC1 = new C1();
     C2 *pC2 = new C2();
     C3 *pC3 = new C3();
     C4 *pC4 = new C4();

    pC1->Dosomething();
}


In that situation, the run will hang on the line creating C4.
If I switch the order of the class creation, It will hang always on the last class creation.

I have looked in the assembly and it remains stuck on teh first instruction for the new which is a mov .

I suppose it might be a memory management issue, but I am not sure where to start with.

last thing is that I dont do anything special in the classes contructors except initializing some members.

If anyone has a clue on what could cause this behaviour, that would be appreciated :)

Lionel.

Outcomes