[Gc] Malloc'd memory pointing to GC malloc'd memory

Alec Orr Alec.Orr at wbemsolutions.com
Thu Dec 23 10:39:56 PST 2004


GC 6.2,
Posix threads
No malloc redirect.
Red Hat Linux 9

Suppose I have a structure with one pointer, and a function to create in 
a NON-GC enabled module (.so):

// holder.h

typedef struct _Holder {
   void *pData;
} Holder;

// holder.c

Holder* makeHolder(void* pData) {

	/* use the NON-GC Malloc to allocate this */
	Holder *holder = (Holder*)malloc(sizeof(Holder));
	holder->mData = pData;
	return holder;

In a main .exe (or another .so) I have a GC enabled module:

void main() {
	void* data = GC_MALLOC(100);
  	Holder* holder = makeHolder(data);
	/* force a garbage collect */

	/* At this point, we have not freed the 'holder' variable, but will 
'data' be marked as free'd by the GC? */	

If a pointer (to GC allocated memory) resides in a module that was not 
allocated with the GC, will the GC see it?  If not, is there a way I can 
inform the Garbage Collection scanner, hey, in addition to the stack, 
static area, and YOUR heap, search this area over here too?  My guess is 
no, but I wanted to check.  Are these my options?

1.  Build the Garbage collector with REDIRECT_MALLOC
2.  Use a memory interposer (the same as 1 essentially)
3.  Require that the Holder module have some kind of function pointer 
table the main exe must populate with malloc, free, realloc pointers (to 
GC equivalents?).

Thanks for any input folks and have a great holiday,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 4686 bytes
Desc: S/MIME Cryptographic Signature
Url : https://napali.hpl.hp.com/pipermail/gc/attachments/20041223/256d078f/smime.bin

More information about the Gc mailing list