Wed, 5 Nov 2003 10:50:13 -0800
GC_base() is the standard way to test. The loop in its implementation
is almost never executed, so it essentially runs in constant time.
What you need could be done somewhat faster. If you know that the
pointer is valid, but you're not sure who allocated it,
GC_find_header(p) != 0
should be a faster and uglier way to check that the GC is responsible for it.
But it will succeed for pointers to free chunks in the garbage collected
You will probably have to declare GC_find_header() as returning a void * for
this to work. It's not really meant to be used by client code. But it's
somewhat documented in the debugging instructions, since it tends to be a
useful thing to call from the debugger.
> -----Original Message-----
> From: email@example.com [mailto:firstname.lastname@example.org]On
> Behalf Of Nicolas Cannasse
> Sent: Wednesday, November 05, 2003 3:24 AM
> To: email@example.com
> Subject: [Gc] GC_is_ptr
> Hello list,
> Is there any (fast) way to tell if a pointer have been
> allocated by the GC ?
> Actually I'm using GC_base(p) != NULL to test it, not sure
> it's the most
> efficient way.
> Nicolas Cannasse
> Gc mailing list