[mercury-users] Registering memory deallocation functions
Peter Ross
pro at missioncriticalit.com
Thu Aug 25 18:08:34 AEST 2005
On Thu, Aug 25, 2005 at 12:49:30PM +1000, Peter Hawkins wrote:
> 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);
>
You can see an example of this code in extras/concurrency/semaphore.m
in the predicate semaphore__new where we need to call a pthread
deallocation routine when the semaphore is no longer needed.
Note the wrapping with #define so that the routine is only called when
compiled in a grade using the boehm gc system.
--------------------------------------------------------------------------
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