Is it possible to configure the heap on which objects allocated using the 'new' keyword are allocated?
What is the default heap?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Is it possible to configure the heap on which objects allocated using the 'new' keyword are allocated?
What is the default heap?
You can define operator new/delete for your own class types and thus where they are allocated: http://en.cppreference.com/w/cpp/memory/new/operator_new
kind regards,
Torsten
You can defined operator new/delete on a per class base or (of cause) for all allocations. But you do not have the information, of what will be places into the newly allocated memory.
But defining operator new/delete could be done with a macro and thus defining for a class from which heap object have to be allocated is just a matter of a single line of code.
If you need to allocate object of the very same type on different heaps, you can use placement operator new. You would to have to allocate the memory first (remember to take the alignment requirements of the type into account) and then construct the object using placement operator new syntax.
In addition, std containers have an additional template parameter (an allocator) that can be used to define, how a container allocates required memory.