4 ms·
I had a friend who worked for one of the big Market Makers, and he told me that they would indeed turn the GC off, but what they'd do is just pre-allocate every
by tombert 3y ago
I had a friend who worked for one of the big Market Makers, and he told me that they would indeed turn the GC off, but what they'd do is just pre-allocate everything into bigass arrays before-hand, and have incrementers to simulate the "new" keyword. They might do this in something more or less like a threadlocal to avoid having to deal with locks or race conditions or anything like that.
- shortrounddev2 3y agoA lot of game engines do this, avoiding the cost of a malloc lookup by just allocating everything as a stack
- tarnith 3y agoSeen some audio engines that do this too. You can come up with an elegant non-blocking lock free allocator and pass updates from the user thread out to system and reserve the memory, or you can just up front allocate everything that's needed. If it's a fixed function synth, sometimes just allocating everything up front makes more sense.
- gabesk 3y agoKernel drivers, too. Especially the DMA buffers for devices that don’t support scatter gather: if you don’t allocate them at driver startup, you might not be able to find enough free contiguous regions later. Although maybe that’s not as big of a deal these days, since both Windows and Linux can relocate physical pages.
- wtracy 3y agoI remember seeing a Java game engine that included a container that you were supposed to dump unused objects into to prevent GC from running in the middle of a level. At the end of the level, you could empty the container, and let the GC run during the loading screen or whatever. It was a deliberate design choice that was surprisingly close to what the original article describes.
- junon 3y agoThis is called bump or arena allocation, depending on how you want to define it.
- Too 3y agoSometimes also referred to as Object pools.
- erik_seaberg 3y agoThis is like going back to malloc and free but using array indices rather than pointers, and each type has a fixed-size heap. We did it in one Microsoft service because the very first .NET releases had slow GCs.
- Karellen 3y agoOne could argue that pointers are just array indices, where the array is your whole address space, and you only get the one array for all your types.
- erik_seaberg 3y agoIt helps that pointer-to-T is a distinct type, where (apart from Ada) index-into-array-of-T is just like any other integer.
- limaoscarjuliet 3y agoStandard approach in systems for critical applications like aerospace: https://www.quora.com/How-does-SpaceX-handle-memory-management-when-programming-in-C-for-their-rockets https://www.quora.com/How-does-SpaceX-handle-memory-manageme...