[Gc] strange problem: GC needs manually calling to GC_gcollect()?

Zhang Le 69dbb24b2db3daad932c457cccfd6 at gmail.com
Wed Jul 13 13:29:55 PDT 2005


> > I have one more question. Will the memory be collected
> > correctly if I offset the pointer:
> > double* p = GC_MALLOC(sizeof(double)*100);
> > p += 50;
> > // access p[-10] p[-20], p[30] etc.
> >
> > Here  I offset p to allow the use of negative  index, and p
> > no longer points to the original memory address. Will p still
> > be collected?
> >
> The answer is "It depends".  In the default configuration,
> with GC_all_interior_pointers set, and assuming the offset pointer
> still points into the object, the answer is yes, it will work.
> If p is stored on the stack, and points inside the object, the
> answer is also yes.  If p is stored elsewhere, and
> GC_all_interior_pointers is not set, you need to look at
> GC_register_displacement().
Sounds very complex. My current solution is to keep to  original
address being pointed using another pointer:
  double* p_data = GC_MALLOC(sizeof(double)*100);
 double* p = p_data + 50;
 // access p[-10] p[-20], p[30] etc.
I think it will work at least for this example. 

I will look at the functions you mentioned, since one malloc wrapper I
use makes use of  such tricks to store some magic info, and simply
redefining malloc/free to GC_MALLOC/GC_FREE does not work.

Zhang Le



More information about the Gc mailing list