[gambit-list] Gambit FFI reference counting
Phil Dawes
pdawes at users.sf.net
Thu Feb 8 16:48:43 EST 2007
The trickiest thing I found writing Gambit FFI code[1] was managing memory.
After flailing around a bit scratching my head over memory leaks and
crashes I found the best technique was to check the reference counts of
objects as much as possible. Gambit doesn't appear to have a function to
peek the refcount of a "STILL" allocated object, so I created a simple
one in my code:
int _peek_refcount(___SCMOBJ s){
#define ___STILL_BODY_OFS 6
#define ___STILL_REFCOUNT_OFS 1
return ___UNTAG(s)[___BODY_OFS - ___STILL_BODY_OFS +
___STILL_REFCOUNT_OFS];
}
I then littered the code with assert calls. e.g:
assert(1 == _peek_refcount(myobj));
Hope this helps somebody,
Phil
[1]
https://webmail.iro.umontreal.ca/pipermail/gambit-list/2007-February/001112.html
More information about the Gambit-list
mailing list