lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Am 27.06.2018 um 10:08 schröbte Tim Hill:

— Add an internal “array length” value to each table (very much like the old getn/setn). And no, in most cases this will NOT add memory overhead given the granularity of most help allocators these days.

I'd say the expected memory overhead for an additional 32bit array length field is 4 bytes. It may fit into the memory block that's allocated anyway (due to granularity), or it may just overflow the block and cause a larger memory overhead (also due to granularity). Without knowing the current table size and the granularity of your memory allocator that's all you can say.

Now, the current size of an empty table is 56 bytes in Lua 5.3 on amd64. That's a multiple of 8 but not 16, so if the memory allocator's granularity is 16, then a 4 byte (or even 8 byte) array length field is for free. If the granularity is 8 bytes, the array length field will cost 8 bytes.

The dlmalloc allocator we talked about recently has an 8-byte granularity.



p.s.: An extra array length field might still be a good option despite the potential memory overhead.