[Gc] Determining if pointer GC allocated

Bruce Hoult bruce at hoult.org
Wed Dec 21 04:00:42 PST 2011

On Thu, Dec 22, 2011 at 12:53 AM, Hans Aberg <haberg-1 at telia.com> wrote:
> On 21 Dec 2011, at 01:35, Henning Makholm wrote:
>>> Is there a function to check if a pointer has been allocated by the
>>> 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 on
the order of 10 memory references.

More information about the Gc mailing list