I'm writing a memory manager with its own garbage collector. The garbage collector (GC for short) moves objects in memory to reduce fragmentation of free space. Of course, each time I call the GC, the pointers to allocated objects are no longer valid, since the objects pointed to have moved. So I've written a template class Pointer <class T> for use instead of T*.
But I find that rather tricky to use (reduces greatly the lisibility of the code) and the standard malloc routine works fine with ordinary pointers, even on an OS that has a GC ! My questions are : how do they do to work with ordinary pointers without meeting problems ? and, can I do the same ? Or is it necessary for me to work with a tricky Pointer class ?
Thanks in advance !