You need to use alloocation system programs, which are not a huge deal, as you also use the system-dependent mremap function. However, you also need to be careful what you place in memory (for example, using placement new will not work well), because mremap can change the memory address when resizing.
Since you are most likely using Linux to do this, have you considered the anonymous mmap region? This will behave just like malloc, except that it is automatically paged.
source share