[Gc] Determining if pointer GC allocated
hans.boehm at hp.com
Wed Dec 21 16:07:49 PST 2011
IIRC, GC_base() is avoided on the most frequently exercised paths in the collector, though those do very similar things using essentially the same data structures. But it is essentially a short piece of straight-line code, so it should indeed be quite fast. Slight improvements are probably possible if you know that the argument is a base pointer. If you assume the argument is a pointer to a valid object, GC_find_header() != 0 might be a bit faster, though it uses an interface that's not currently exported.
> -----Original Message-----
> From: gc-bounces at linux.hpl.hp.com [mailto:gc-bounces at linux.hpl.hp.com]
> On Behalf Of Hans Aberg
> Sent: Wednesday, December 21, 2011 5:23 AM
> To: Bruce Hoult
> Cc: gc at linux.hpl.hp.com; Henning Makholm
> Subject: Re: [Gc] Determining if pointer GC allocated
> On 21 Dec 2011, at 13:00, Bruce Hoult wrote:
> >>>> Is there a function to check if a pointer has been allocated by
> >>>> GC? That is, something like
> >>>> bool is_on_heap(void* p);
> >>>> that returns true exactly when p has been allocated by the GC.
> >>>> And would such a function be time consuming?
> >>> Check whether GC_base(p) returns 0.
> >> Thanks! I saw this function, but did not realize it could be used.
> >> How time-consuming is this call?
> > It's used in the inner loop of the marking phase in the GC, so much
> > effort is made to make it fast!
> > Without actually reading the source code right now, I'd guess it is
> > the order of 10 memory references.
> Would it be possible to implement a significantly faster function that
> just checks if the pointer is GC allocated, rather than finding the
> Gc mailing list
> Gc at linux.hpl.hp.com
More information about the Gc