| www.delorie.com/archives/browse.cgi | search |
| From: | "Mark E." <snowball3 AT bigfoot DOT com> |
| To: | gcc AT gcc DOT gnu DOT org |
| Date: | Sun, 7 May 2000 11:33:06 -0400 |
| MIME-Version: | 1.0 |
| Subject: | Re: Perfomance of gc-simple |
| CC: | lauras AT softhome DOT net, djgpp-workers AT delorie DOT com |
| Message-ID: | <39155472.28917.25EC84@localhost> |
| References: | <3913BE88 DOT 44A89056 AT softhome DOT net> |
| X-mailer: | Pegasus Mail for Win32 (v3.12c) |
| Reply-To: | djgpp-workers AT delorie DOT com |
> > 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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |