Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can't do dynamic memory with that, right? Not without a custom malloc implementation. So it's not all that comparable to pickle.
 help



Most modern C runtime libraries on POSIX OSes implement malloc() and friends using the mmap() system call.

I 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.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: