This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: Making GC aware of overall allocation?
- To: Lars Arvestad <arve at nada dot kth dot se>
- Subject: Re: Making GC aware of overall allocation?
- From: Michael Livshin <mlivshin at bigfoot dot com>
- Date: 02 Nov 1999 12:23:38 +0200
- Cc: guile at sourceware dot cygnus dot com
- Organization: who? me?
- References: <yue1za9e2nt.fsf@turing.nada.kth.se>
Lars Arvestad <arve@nada.kth.se> writes:
> [ summary: how to make the Guile GC aware of (some of) user's mallocs ]
the primitive mechanism in Guile is the function `scm_done_malloc'.
it takes a number, which is supposed to be the malloced size. it
can be negative, so that you can say to the GC how much memory you
just freed.
it's probably a good idea to provide some sort of malloc/free wrappers
with this bookkeeping, if you can put up with wasted space, something
like this (written on the spot, untested)
/* maximum alignment on your system, the below is good for x86 */
#define SCM_MAX_ALIGN 4
void *
scm_sys_malloc (scm_sizet size, char const *what)
{
void *res = malloc (size + SCM_MAX_ALIGN);
SCM_ASSERT (res, SCM_MAKINUM (size), what);
*((long *)res) = (long)size;
scm_done_malloc ((long)size);
return res + SCM_MAX_ALIGN;
}
void
scm_sys_free (void *ptr_)
{
void *ptr = ptr_ - SCM_MAX_ALIGN;
scm_done_malloc (0 - *((long *)ptr));
free (ptr);
}
> Best regards,
> Lars
hth,
--mike
--
Don't trust these UNIX people. They are all demons. They kill their
parents and fork children. I don't know how they could do this with
their balls cut off but they manage. -- anonymous