Possible duplicate:
How to implement garbage collection in C ++
I recently asked this question in an interview on how to implement a garbage collector in C ++.
My answer was to have a pre-allocated memory pool and build an object in this allocated space. Also for storing the size of memory allocated for an object in a byte preceding the memory location pointed to by the pointer.
The interviewer was not satisfied with the answer.
Later I realized that my solution was actually trying to avoid the main goal of the garbage collector by first allocating the memory pool and working with this memory.
But I think it would be difficult to implement a garbage collector in C ++ without the need to modify the compiler.
Any suggestions? Thanks in advance.
EDIT
It seems that someone else also faced a similar problem, and many smart guys shed their views here
source
share