slab allocator
A memory manager that reserves one large block up front and hands out small pieces of it, avoiding many tiny allocations.
In more detail
Node.js keeps an 8 KiB pool, set by Buffer.poolSize, for Buffer.allocUnsafe() and Buffer.from(): requests smaller than half the pool, under 4 KiB, are cut from it. Keeping even a tiny slice alive keeps the whole 8 KiB block from being freed.
Related terms
- Buffer — A Node.js object holding a fixed-length run of raw bytes stored outside the V8 heap; more generally, any memory that holds data on its way somewhere.
- Buffer.alloc() and Buffer.allocUnsafe() — The two ways to create a new Buffer of a given size: alloc() fills it with zeros, while allocUnsafe() skips that step and may contain old data.
- memory fragmentation — Free memory broken into many small scattered gaps, so a large block cannot be allocated even though enough memory is free in total.
Taught in
- Buffer Fundamentals: Slab Allocator & V8 Memory — Node.js Internals & Backend Services
- Buffer Encodings: UTF-8, Hex, Base64 & Slicing — Node.js Internals & Backend Services