[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Common allocation sizes for Lua
- From: Thomas Harning <harningt@...>
- Date: Thu, 11 Sep 2008 01:19:39 -0400
Just wondering... are there any common allocation sizes for Lua that
could perhaps take advantage of a memory pool (like boost's.. only
coded in C instead)?
Boost's memory pool template class has the interesting property that
it stores the free list interleaved in the data such that you end up
w/ structures like this.
NEXTFREE -> A
A FREE->B
B FREE->D
C DATA
D FREE->NULL (requires another memory block)
E DATA
F DATA
Allocating requires simple ptr arithmetic that can be carried over
such that multiple items can be allocated to handle arrays of data
that are larger than a unit size.
Example Malloc:
ret = *nextfree; // ret = A
nextfree = *ret; // nextfree = B
return ret
Example free (non-ordered... ordered would be used if you want to do
arrays of data w/ O(N) rather than O(N^2) or high fail-rate
//freed = A
*freed = *nextfree; // A => B
nextfree = freed; // nextfree = A
Has anybody seen any library like this already for C? I've generally
only seen linked-list style implementations that require separate
storage.
Also... has anybody seen a way to calculate the LCM at compile-time
for C? This is the way that the boost pool gets its allocation unit-
size to get a safe alignment...
At compile-time, i suppose a union w/ { void*, DATATYPE, size_t } /*
size_t for the end of the structure to handle linking to the next
major block */ would get me proper alignment right... run-time would
require runtime LCM anyways.....
To see what I'm looking at as theory/impl reference:
http://www.boost.org/doc/libs/1_36_0/libs/pool/doc/concepts.html
http://www.boost.org/doc/libs/1_36_0/libs/pool/doc/implementation/alignment.html