by codr4life · 10y ago · 0 comments
I was asking, "I don't think an allocator should need to store the buffer size internally; why not formulate the challenge so that the block size doesn't need to be stored?"
buf=malloc(128);
free(buf, 256);
seems dangerous, if free can't check the size.But kernels sometimes do just that ( free(ptr, size) ), for performance reasons and because "kernel writers know what they are doing".
And you don't need to store the size. The slab allocator doesn't store any information except how far into the current slab it's already dished out memory.