This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Perfomance of gc-simple
- To: gcc at gcc dot gnu dot org
- Subject: Re: Perfomance of gc-simple
- From: "Mark E." <snowball3 at bigfoot dot com>
- Date: Sun, 7 May 2000 11:33:06 -0400
- CC: lauras at softhome dot net, djgpp-workers at delorie dot com
- References: <3913BE88.44A89056@softhome.net>
> > I recall Alexandre Oliva starting discussion about making gc-page use simple
> > malloc(), what about that?
>
> You can easily use malloc() instead of mmap(). Just call malloc() with
> size+page_size-1 and align the return value.
What about a vmalloc that wraps calls to malloc?
Here is a crude implementation I came up with:
vmalloc_wrap.c:
#include <stdlib.h>
#include <unistd.h>
#ifndef HAVE_VMALLOC
#define VMALLOC_FREE(x) vmalloc_free (x)
static const unsigned int ptr_size = sizeof(char *);
void *
vmalloc (size_t size)
{
char *unaligned_ptr, *aligned_ptr;
int page_size = getpagesize();
/* Provide space for aligning the returned pointer. */
size += page_size - 1;
unaligned_ptr = malloc (size);
/* Now align the pointer. */
aligned_ptr = (char *)((unsigned long)(unaligned_ptr + page_size) & ~(page_size -
1));
/* Record location to pass to free() in unused allocated space. */
*((char **)(aligned_ptr - ptr_size)) = unaligned_ptr;
return aligned_ptr;
}
void
vmalloc_free (void *aligned_ptr)
{
/* Recover the pointer allocated with malloc. */
char *unaligned_ptr = *(char **)((char *)(aligned_ptr - ptr_size));
free (unaligned_ptr);
}
#else
#define VMALLOC_FREE(x) free (x)
#endif
Then use VMALLOC_FREE in ggc-page.c instead of free.
Mark