On 10/3/2018 at 4:35 AM, mychii said:
The current best solutions are either modifying the containers, or make my own.
I too had trouble understanding what you were getting at, I think your issue is you want to use e.g. a vector, but have the memory it uses be relocatable.
I don't know STL super well internally as I tend to use my own template library these days (writing your own is quite doable, especially for POD types), but it hopefully wouldn't be a big deal to change the array start pointer yourself, even adding a public function for this. Whether you'd get any issues with parts of the STL code having dangling pointers, I don't know.
You could wrap all the references to the array start through an accessor function and see where it gets called, or override it to use your handle (which is a bit inefficient). You would have to be careful where and when you changed the array pointer, so there were no dangling pointers or maybe multithreaded code trying to access the vector at the same time.
Whether all this is the right solution for your problem is another matter. Usually I would think that a specific / alternative solution for your problem would tend to be a better bet, unless you are trying to create some kind of all singing, all dancing environment for others to use (e.g. multi-purpose engine / scripting language), and you have profiled this type of approach as being beneficial.
Bear in mind also that a lot of platforms these days offer virtual memory address space, so 'fragmentation' may not affect things in the same way as a flat address space.