4 ms·
I think the idea is that so you have memory that is invisible to the Go GC. That way you are free (and at risk of memory leaks) to do whatever you want with tha
by chewxy 6y ago
I think the idea is that so you have memory that is invisible to the Go GC. That way you are free (and at risk of memory leaks) to do whatever you want with that slab.
- mish15 6y agoYou can do this in pure Go though, you just need to manage the allocator yourself. That is a significant technical undertaking, but once done the advantages are huge. No GC overhead, no cgo. Done properly you can even have multiple readers and writers working concurrently in the same allocation space.
- chewxy 6y agoOK you piqued my curiosity. How?
- yencabulator 6y agomalloc isn't magic, just mmap some memory to dole out.
- mish15 6y agoYou just mmap memory as a slice. You can grow and shrink it, flush to disk if backed by a file, etc. In code it’s just a slice. Tough part is you need to allocate, control bounds, binary encode/decode, struct align, defrag, etc. It’s hard work, but the performance is 100% worth it if performance is your main goal.
- chewxy 6y agoTIL mmap'd memory is invisible to Go's GC