5 ms·
The excellent I/O library, Netty, deals with this by allocating a slab of direct memory, slicing it up and pooling the use of the memory. It's the Java equival
by gresrun 15y ago
The excellent I/O library, Netty, deals with this by allocating a slab of direct memory, slicing it up and pooling the use of the memory.
It's the Java equivalent of writing your own alloc().
- pron 15y agoThat's not exactly what Netty does. It does allocate large direct buffers and slices up pieces, but the pieces are not pooled because they are never returned to Netty. For this reason they also don't need to implement malloc in Java. All the slices reference the "parent" buffer, and once they are all collected, the parent can be collected as well. When there is no more room in the buffer, another one is allocated. (I just read that code last week because I wanted to know what was going on precisely because there was no way of returning a sliced buffer to the pool). It is very easy (and efficient) to implement java.io input and output streams backed by a buffer (as long as the buffer doesn't have to grow).
- gresrun 15y agoBuffer pooling is still very much a WIP. (the first commit was 3 days ago!) https://github.com/netty/netty/tree/bufferpooling https://github.com/netty/netty/tree/bufferpooling https://github.com/netty/netty/issues/62 https://github.com/netty/netty/issues/62 https://github.com/netty/netty/commit/c9968d6cbfa958f73a98688b6d71571f32a3086d https://github.com/netty/netty/commit/c9968d6cbfa958f73a9868...
- pron 15y agoOh! Good to know!