
23 Apr
2009
23 Apr
'09
4:04 p.m.
Kasra wrote:
auto_ptr<char*> traced_buffer(new (gc_traced) char[1024]); This raises undefined behaviour, I believe.
gc allocated memory slab is always zero, so there would be no live pointers on the traced_buffer memory slab.
C++ doesn't allow you to call delete on a pointer type you allocated with new some_array_type, whether the type of the elements is a POD or not. That is what raises the undefined behaviour here. If you test your code with a type that traces construction and destruction, you will see only the first element of the array gets destructed, which is incorrect. Or your program might just crash.