3 ms·
Afaik, a malloc is not guaranteed to return fast. With those requirements it's hard even in C.
by chopin 4y ago
Afaik, a malloc is not guaranteed to return fast. With those requirements it's hard even in C.
- cozzyd 4y agoRight but you would typically use a preallocated arena.
- chii 4y agobut if you're going to do that, the same could be done with java, with less pain for the remaining parts of the application that does not require such methods of memory allocation.
- cozzyd 4y agoMy Java is rusty, does Java provide things like placement new that make using arenas ergonomic?
- chii 4y agono, you cannot control allocation via regular means. What i meant is that you make pooling in java, and that effectively makes it work like an arena allocator (in that you end up setting a bit/boolean flag to allocate/deallocate an object). But the pooling can be constrained to just one portion of your app - the hot loop or the bit that needs the low latency. The remaining code - loading resources at startup for example - can just be regular old java that's easy to write.
- chopin 4y agoPooled JDBC connections work this way in Java.