cancel
Showing results for 
Search instead for 
Did you mean: 

new vs malloc - surprising results with IAR

ranran
Senior II

Hello,

Recently I started using c++ application with STM32, and I encounter a very strange behavior:

It seems that after 1-3 calls to new() operator the new operator call get hang somewhere into assembly. When I try to step into the problematic new call it just gives assembly window and I can't reach anywhere in C the new call statement.

I suspected it is a heap issue, though I should have enough heap size for the new call.

But on replacing with malloc - even much bigger size - malloc call is always successful !

After a lot of debug, I gave up, and replaced the new call with static initialization.

I also checked the c++ settings, but I see nothing which can explain this failure of new operation.

The c/c++ code is configured with override in the relevant folder group in IAR.

After a whole day of debugging of this issue, I still have no clues about it :(

Did anyone encounter this behavior ? Any idea ?

Regards,

ranran

1 REPLY 1

Disassemble the whole thing, or use a listing file, such that you can associate "somewhere" with specific functionality, like the allocator or constructors.​

Understand how the memory arena is described by internal structures, and walk it. Determine if any of your code is exceeding or damaging the arena. Add instrumentation and sanity checking to follow or contain the failure mechanism.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..