2018-06-19 03:10 AM
Hi All,
I'm working on STM32L4 MCU in CPP project(cubeMX code that c code i convert to cpp), i have one doubt in NEW operator, i create array of pointer object and i build code no error but while debugging i got Hard Fault error .
code:
header.h:
class cRcdMaker
{protected:
cRecorder* mRecorders[3 ]; //
cRecorder class
};code.cpp:
for ( i = 0; i < mNumSimultaneousRecorders; i++ )
{ mRecorders[1] = new cRecorder(); }2018-06-19 04:52 AM
So sufficiently large heap, or enough memory generally?
Like all Hard Faults, go look at the processor registers, and the disassembled code at the fault
2018-06-19 05:11 AM
As Clive says, check the heap size. How large is cRecorder? Are these the only dynamic allocations in the program? Is it the first allocation which fails (this might indicate a fault other than heap exhaustion)? Assuming sufficient memory operator new should work just fine, but it's worth stepping into the implementation to see what it actually does.
Personally, I rarely use dynamic allocation partly because of concerns about heap fragmentation. I suppose it depends on the application, but I don't generally have non-local objects with limited lifetimes anyway. Do your objects genuinely have lifetimes shorter than the application?2018-06-19 07:08 AM
So sufficiently large heap, or enough memory generally?
I have often seen a default heap size of zero generated by toolchains.