In my IAR Embedded workbench project, the icf file already defines a block HEAP, say, from 0x30000000 to 0x40000000, and normally a C++ object created via "new" will be placed in HEAP. But I am wondering if I could create some particular (not all) C++ object in a region different than HEAP, say, "SPECIAL_HEAP" from 0x50000000 to 0x60000000? If possible, how to do this?
Asked
Active
Viewed 50 times
0
-
Probably not without coding your own "SPECIAL HEAP manager". – Some programmer dude Aug 23 '22 at 13:12
-
IIRC those kinds of compilers provided modifiers such as `xdat` `idat` etc – Den-Jason Aug 23 '22 at 13:13
-
You should provide more detail: What exactly do you not know? What are you trying to do? IAR definitely allows manual memory placement, but it is unclear what would be the best way for you. – user694733 Aug 24 '22 at 07:33
-
@user694733, In my current project, a C++ object created dynamically via new will be placed in the heap defined in .icf, say, 0x30000000 and 0x40000000, which is working fine, and I want to keep it that way for *most* of C++ objects. But I do want to place some particular dynamically created C++ object in another memory, say, 0x50000000 to 0x60000000. So basically, I want two heaps, one heap for normal C++ objects created via new operator, and a 2nd heap to place some particular objects. Is this 2nd heap possible? And how can I control objects' creation so that they are in the 2nd heap? – Work Only Aug 26 '22 at 03:28
-
BTW, my project is running FreeRTOS on ARM – Work Only Aug 26 '22 at 03:34
-
FreeRTOS has its [own heap mechanism](https://www.freertos.org/a00111.html), which can be separate from the one provided by compilers standard library. Why not use that? – user694733 Aug 26 '22 at 07:38
-
But, having multiple heaps sounds really unnecessary. Typically embedded projects which do not run in hosted environments try to manage without dynamic allocation at all, and use just stack and static allocation instead. One other alternative could be using C++:s [placement new](https://stackoverflow.com/q/222557/694733) with static allocated objects that are manually placed in your new memory region. You should re-evaluate if you really need 2 heaps. – user694733 Aug 26 '22 at 07:49