3 ms·
Most modern C runtime libraries on POSIX OSes implement malloc() and friends using the mmap() system call.
by bregma 7mo ago
Most modern C runtime libraries on POSIX OSes implement malloc() and friends using the mmap() system call.
- jim33442 7mo agoI mean in your C code that's using mmap, I know you can do this with a custom malloc impl, but idk if there's a built-in way: int len = 1000; int file = open("numbers.void", O_RDWR | O_CREAT, 0600); ftruncate(file, len); void\* buf = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, file, 0); // Treat mmapped buffer as a heap initialize_heap(buf); // Manage dynamically-sized array on disk int* my_array = malloc(sizeof(int) * 8, buf); my_array = realloc(my_array, sizeof(int) * 16, buf); free(my_array, buf); Protobuf, Python pickle, etc can all handle dynamic memory that gets flattened when you want to serialize.