Reference Information. We use Keil to compile our NXP LPC2458 project. There are many tasks that are performed on Keils RealView RTOS. A stack space has been created that is allocated for each task. There is no default HEAP, and I want to avoid it, because we cannot afford the overhead of code and the cost of "garbage collection"
Goal: use C ++ in embedded code without using heap. Keil provides #pragma (__use_no_heap), which prohibits the binding of malloc () and free () calls.
Solution: I tried creating a Singleton with a private static pointer. My hopes were that new () would not be called, as I declared dlmData static in getDLMData (). For some reason, the linker still claims that malloc () and free () are being called. I have the thoughts of the private operator new () and the private operator delete (), and then declaring dlmData as static in an overloaded function. For some reason it does not work. WHAT IS I DEFAULT?
//class declaration class DataLogMaintenanceData { public: static DataLogMaintenanceData* getDLMData(); ~DataLogMaintenanceData() { instanceFlag = FALSE; } protected: DataLogMaintenaceData(); //constructor declared protected to avoid poly private: static Boolean instanceFlag; static DataLogMaintenceData *DLMData; } //set these to NULL when the code is first started Boolean DataLogMaintenanceData::instanceFlag = FALSE; DataLogMaintenanceData *DataLogMaintenaceData::DLMData = NULL; //class functions DataLogMaintenanceData *DataLogMaintenanceData::getDLMData() { if (FALSE == instanceFlag) { static DataLogMaintenanceData dlmData; DLMData = &dlmData; instanceFlag = TRUE; return DLMData; } else { return DLMData; } } void InitDataLog ( void ) { DataLogMaintenanceData *dlmData; dlmData = DataLogMaintenanceData::getDLMData(); // to avoid dlmData warning dlmData = dlmData; } //ACTUAL TASK __task DataLog() { .. .. .. code to initialize stuff InitDataLog(); .. .. ..more stuff }
For some reason, the only way I can put this together is to create a bunch of space and then allow compilation of malloc () and free () into the project. As expected, the “static” associated object, dlmData, is located in the RAM space allocated for the dataLog.o module (that is, it does not live in HEAP).
I can’t understand, and I checked Google, what am I missing? Is it possible in C ++ to bypass malloc () and free () when compiling clean objects? I know that I can replace the RTOSs implementation of malloc () and free () to do nothing, but I want to avoid compiling in code that I do not use.
source share