harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

segmalloc.ha (307B)


      1 // Allocates a segment.
      2 fn segmalloc(n: size) nullable *void = {
      3 	let p: *void = mmap(null, n,
      4 		PROT_READ | PROT_WRITE,
      5 		MAP_PRIVATE | MAP_ANON, -1, 0);
      6 	return if (p: uintptr: int == -ENOMEM) null else p;
      7 };
      8 
      9 // Frees a segment allocated with segmalloc.
     10 fn segfree(p: *void, s: size) int = munmap(p, s);