Support for memory allocation in uCR is itself written in C++. However, special care must be taken that all the data structures for managing the default heap in particular be in place before any static initializers are called. To arrange for this, the default heap initializer is called separately and ahead of initializers by the startup function of uCR.
The HEAP_SPACE object is an object token like the THREAD type, and represents a segment of heap space from which memory may be allocated. The uCR startup creates an initial HEAP_SPACE object that is used by malloc and non-placement new operators.
Embedded systems often have different kinds of memory, for example SRAM for small private objects, or perhaps synchronous DRAM for manipulation of large images, and so uCR allows programmers to create other heaps in specified sections of address space.
The uCR support for memory allocation adds a placement new operator that takes as a parameter the HEAP_SPACE to use. Because of the way the heap data structures are designed, deallocation does not require a reference to the HEAP_SPACE object that created it. This feature was specifically included to support the delete operator. Any memory allocated with ``new'' or ``new(HEAP_SPACE*)'' can be deleted with ``delete''. This is necessary because ``delete'' cannot be overloaded to take a HEAP_SPACE parameter, and to require such would render ``delete'' unuseable for memory allocated from alternate heaps.