[mercury-users] Registering memory deallocation functions

Peter Hawkins peter at hawkins.emu.id.au
Thu Aug 25 12:49:30 AEST 2005


Hi...
Kral Stefan wrote:

>Do you have any ideas or hints how to register a function 
>that should be called when the GC frees an object of
>a particular type (say, a GMP integer or float)?
>  
>
Yes. You can register finalizers with the Boehm garbage collector that 
get called when an object gets garbage collected. You need to use the 
GC_register_finalizer function.

eg.:

pointer = GC_MALLOC(sizeof(athing));
GC_register_finalizer(pointer, thing_finalizer, 0, 0, 0);

...
void thing_finalizer(void *thing, void *data)
{
    athing *thething = (athing *)thing;

    /* Do something to free thething here */
}

If the object in question wasn't allocated using GC_MALLOC, you might 
need to create a wrapper type around it that is allocated that way. We 
use this technique to wrap the CUDD bdd library.

=)
Peter
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list