parmi wrote on Friday, August 09, 2019:
Thank you so much for the answer Richard!
So I understand that “configUSE_NEWLIB_REENTRANT” would not solve my problem.
I’m thinking about overriding the operator new, delete, new[] and delete[].
void* operator new( size_t size )
{
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED)
{
//what should I do???????
}
return pvPortMalloc( size );
}
void* operator new[]( size_t size )
{
return pvPortMalloc(size);
}
void operator delete( void * ptr )
{
vPortFree ( ptr );
}
void operator delete[]( void * ptr )
{
vPortFree ( ptr );
}
But I’m not sure this is the best solution.
For example, the “string” class can allocate memory dynamically when concatenating a string.
string my_string = string ("Hello");
/* a memory allocation can be performed internally, which operator uses the "string" class? "new" or "malloc(...)"? */
my_string + = "world!"