9 * Use this allocator if you have an object a child writes to that you want
10 * all other processes to see.
12 void * alloc_shared(unsigned int size
)
16 ret
= mmap(NULL
, size
, PROT_READ
| PROT_WRITE
, MAP_ANON
| MAP_SHARED
, -1, 0);
17 if (ret
== MAP_FAILED
) {
18 printf("mmap %u failure\n", size
);
24 void * zmalloc(size_t size
)
30 printf("malloc(%zu) failure.\n", size
);
38 void sizeunit(unsigned long size
, char *buf
)
40 if (size
< 1024 * 1024) {
41 sprintf(buf
, "%lu bytes", size
);
45 if (size
< (1024 * 1024 * 1024)) {
46 sprintf(buf
, "%ldMB", (size
/ 1024) / 1024);
50 sprintf(buf
, "%ldGB", ((size
/ 1024) / 1024) / 1024);