mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 22:29:16 +02:00
adding option to mmap heaps instead of mallocing them
This commit is contained in:
parent
5ee65cd71b
commit
670a4ae67b
3 changed files with 31 additions and 6 deletions
14
gc.c
14
gc.c
|
@ -4,6 +4,10 @@
|
|||
|
||||
#include "chibi/sexp.h"
|
||||
|
||||
#if SEXP_USE_MMAP_GC
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
/* These settings are configurable but only recommended for */
|
||||
/* experienced users, so they're not in config.h. */
|
||||
|
||||
|
@ -171,8 +175,14 @@ sexp sexp_gc (sexp ctx, size_t *sum_freed) {
|
|||
|
||||
sexp_heap sexp_make_heap (size_t size) {
|
||||
sexp_free_list free, next;
|
||||
sexp_heap h
|
||||
= (sexp_heap) malloc(sizeof(struct sexp_heap) + size + sexp_heap_align(1));
|
||||
sexp_heap h;
|
||||
#if SEXP_USE_MMAP_GC
|
||||
h = mmap(NULL, sizeof(struct sexp_heap) + size + sexp_heap_align(1),
|
||||
PROT_READ|PROT_WRITE|PROT_EXEC,
|
||||
MAP_ANON|MAP_PRIVATE, 0, 0);
|
||||
#else
|
||||
h = malloc(sizeof(struct sexp_heap) + size + sexp_heap_align(1));
|
||||
#endif
|
||||
if (! h) return NULL;
|
||||
h->size = size;
|
||||
h->data = (char*) sexp_heap_align((sexp_uint_t)&(h->data));
|
||||
|
|
|
@ -57,6 +57,9 @@
|
|||
/* explicitly free sexps, though. */
|
||||
/* #define SEXP_USE_MALLOC 1 */
|
||||
|
||||
/* uncomment this to allocate heaps with mmap instead of malloc */
|
||||
/* #define SEXP_USE_MMAP_GC 1 */
|
||||
|
||||
/* uncomment this to add conservative checks to the native GC */
|
||||
/* Please mail the author if enabling this makes a bug */
|
||||
/* go away and you're not working on your own C extension. */
|
||||
|
@ -205,6 +208,10 @@
|
|||
#define SEXP_USE_MALLOC 0
|
||||
#endif
|
||||
|
||||
#ifndef SEXP_USE_MMAP_GC
|
||||
#define SEXP_USE_MMAP_GC 0
|
||||
#endif
|
||||
|
||||
#ifndef SEXP_USE_DEBUG_GC
|
||||
#define SEXP_USE_DEBUG_GC 0
|
||||
#endif
|
||||
|
|
16
sexp.c
16
sexp.c
|
@ -290,13 +290,20 @@ sexp sexp_make_context (sexp ctx, sexp_uint_t size) {
|
|||
|
||||
#if ! SEXP_USE_GLOBAL_HEAP
|
||||
void sexp_destroy_context (sexp ctx) {
|
||||
sexp_heap heap;
|
||||
sexp_heap heap, tmp;
|
||||
size_t sum_freed;
|
||||
if (sexp_context_heap(ctx)) {
|
||||
sexp_sweep(ctx, &sum_freed); /* sweep w/o mark to run finalizers */
|
||||
heap = sexp_context_heap(ctx);
|
||||
sexp_context_heap(ctx) = NULL;
|
||||
free(heap);
|
||||
for ( ; heap; heap=tmp) {
|
||||
tmp = heap->next;
|
||||
#if SEXP_USE_MMAP_GC
|
||||
munmap(heap, heap->size);
|
||||
#else
|
||||
free(heap);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -702,11 +709,12 @@ sexp sexp_intern(sexp ctx, char *str) {
|
|||
#if SEXP_USE_HUFF_SYMS
|
||||
res = 0;
|
||||
for ( ; (c=*p); p++) {
|
||||
if ((c < 0) || (c > 127))
|
||||
goto normal_intern;
|
||||
he = huff_table[(unsigned char)c];
|
||||
newbits = he.len;
|
||||
if ((space+newbits) > (sizeof(sexp)*8)) {
|
||||
if ((space+newbits) > (sizeof(sexp)*8))
|
||||
goto normal_intern;
|
||||
}
|
||||
res |= (((sexp_uint_t) he.bits) << space);
|
||||
space += newbits;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue