Using C++ std::vector in task
Hello. I am new to FreeRTOS and I am experiencing weird behaviour when targeting an ARM STM32L (M3 core-based) board.
I have compiled FreeRTOS with IAR workbench in C (works fine). I added a C++ file, and set it to compile with the C++ compiler (compiles fine).
From main, I have:
~~~~
extern “C” void do_test(void*);
void main(void)
{
xTaskCreate( dotest, (signed char*)”dotest”, configMINIMALSTACKSIZE, NULL, tskIDLE_PRIORITY+1, NULL );
vTaskStartScheduler();
for ( ;; );
}
~~~~
In the C++ file, I have:
~~~~
include
class my_c {
unsigned int i;
};
extern “C” void dotest( void* p )
{
myc c;
// std::vector doubles;
for (;; );
}
~~~~
If I leave the call to create the vector<> commented out, everything works fine and I can step through with the debugger without a hitch, even though the program doesn’t really do anything of value.
However, if I uncomment the vector<> declaration, the program will hang before it even gets to main().
Any help would be greatly appreciated.
Thanks,
George
include
class my_c {
unsigned int i;
};
extern “C” void dotest( void* p )
{
myc c;
// std::vectorUsing C++ std::vector in task
HI,
De : George Ryan Envoyé : 24 octobre 2013 10:38 À : [freertos:discussion] Objet : [freertos:discussion] Using C++ std::vector in task Hello. I am new to FreeRTOS and I am experiencing weird behaviour when targeting an ARM STM32L (M3 core-based) board. I have compiled FreeRTOS with IAR workbench in C (works fine). I added a C++ file, and set it to compile with the C++ compiler (compiles fine). From main, I have: extern “C” void do_test(void*); void main(void) { xTaskCreate( dotest, (signed char*)”dotest”, configMINIMALSTACKSIZE, NULL, tskIDLE_PRIORITY+1, NULL ); vTaskStartScheduler(); for ( ;; ); } In the C++ file, I have:include
class my_c {
unsigned int i;
};
extern “C” void do_test( void* p )
{
my_c c;
// std::vector doubles;
for (;; );
}
Have you Overload the new opérator ? If not, you should.
If I leave the call to create the vector<> commented out, everything works
fine and I can step through with the debugger without a hitch, even though
the program doesn’t really do anything of value.
However, if I uncomment the vector<> declaration, the program will hang
before it even gets to main().
Any help would be greatly appreciated.
Thanks,
George
here is a copy of my overloader operator to get it working on my application
// Define the ‘new’ operator for C++ to use the freeRTOS memory management
// functions. THIS IS NOT OPTIONAL!
//
void *operator new(size_t size){
void *p;
Using <https://sourceforge.net/p/freertos/discussion/382005/thread/93928e86/?limit =25#a4d0> C++ std::vector in task
Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/freertos/discussion/382005/ To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/ — This message has been scanned for viruses and dangerous content by http://www.mailscanner.info/ MailScanner, and is believed to be clean.
De : George Ryan Envoyé : 24 octobre 2013 10:38 À : [freertos:discussion] Objet : [freertos:discussion] Using C++ std::vector in task Hello. I am new to FreeRTOS and I am experiencing weird behaviour when targeting an ARM STM32L (M3 core-based) board. I have compiled FreeRTOS with IAR workbench in C (works fine). I added a C++ file, and set it to compile with the C++ compiler (compiles fine). From main, I have: extern “C” void do_test(void*); void main(void) { xTaskCreate( dotest, (signed char*)”dotest”, configMINIMALSTACKSIZE, NULL, tskIDLE_PRIORITY+1, NULL ); vTaskStartScheduler(); for ( ;; ); } In the C++ file, I have:
include
class my_c {
unsigned int i;
};
extern “C” void do_test( void* p )
{
my_c c;
// std::vectorifdef USE_FREERTOS
if(uxTaskGetNumberOfTasks()) p=pvPortMalloc(size); else p=malloc(size);else
p=malloc(size);endif
ifdef __EXCEPTIONS
if (p==0) // did pvPortMalloc succeed? throw std::bad_alloc(); // ANSI/ISO compliant behaviorendif
return p; } // // Define the ‘delete’ operator for C++ to use the freeRTOS memory management // functions. THIS IS NOT OPTIONAL! // void operator delete(void *p){ifdef USE_FREERTOS
if(uxTaskGetNumberOfTasks()) vPortFree( p ); else free( p );else
free( p );endif
p = NULL; } void *operator new[](size_t size){ void *p;ifdef USE_FREERTOS
if(uxTaskGetNumberOfTasks()) p=pvPortMalloc(size); else p=malloc(size);else
p=malloc(size);endif
ifdef __EXCEPTIONS
if (p==0) // did pvPortMalloc succeed? throw std::bad_alloc(); // ANSI/ISO compliant behaviorendif
return p; } // // Define the ‘delete’ operator for C++ to use the freeRTOS memory management // functions. THIS IS NOT OPTIONAL! // void operator delete[](void *p){ifdef USE_FREERTOS
if(uxTaskGetNumberOfTasks()) vPortFree( p ); else free( p );else
free( p );endif
p = NULL; } /* Optionally you can override the ‘nothrow’ versions as well. This is useful if you want to catch failed allocs with your own debug code, or keep track of heap usage for example, rather than just eliminate exceptions. */ void* operator new(std::sizet size, const std::nothrowt&) { return malloc(size); } void* operator new[](std::sizet size, const std::nothrowt&) { return malloc(size); } void operator delete(void* ptr, const std::nothrow_t&) { free(ptr); } void operator delete[](void* ptr, const std::nothrow_t&) { free(ptr); } Regards JonathanUsing <https://sourceforge.net/p/freertos/discussion/382005/thread/93928e86/?limit =25#a4d0> C++ std::vector in task
Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/freertos/discussion/382005/ To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/ — This message has been scanned for viruses and dangerous content by http://www.mailscanner.info/ MailScanner, and is believed to be clean.