J
jacob navia
Hi
I am not an IUT student, and I do not have a question, but I have some
answers.
The standard memory allocation strategy of C is to keep track of each
and every piece of RAM. This is an incredibly error prone activity, as
proved by the countless memory allocation bugs that appear in code built
using that strategy.
Another strategy, and the one that I have been proposing here since some
years, is to use the garbage collector and get rid of most problems.
There is an intermediate strategy however, based on pools of memory.
Normally you have a set of related allocations, that can be done from a
memory pool, that is released in a single call when the module that uses
the pool is finished or when the activity associated with the pool is
finished.
A pool, for instance, is handy for a hash table with variable length
keys and variable lengths objects. When the hash table is destroyed, all
the memory that it required can be freed with a single call to pool destroy.
Many other applications are possible. Normally, all big applications are
built with modules that are more or less independent and could benefit
from pooled allocation. In a database application all memory used by one
query can be pooled and released when the query is done.
An example of pool management is in the Apache Runtime (APR) library.
There, the module apr_pools.c proposes a sophisticated interface for
pooled memory management. That library can be downloaded at no cost,
and its license is quite liberal. I adapted some of the code for the
container library, reducing the size of the module to just 1K (1076
bytes when compiled with lcc-win) from around 40K of the original.
The reduced interface proposes
newPool (create a pool)
PoolAlloc (allocate)
PoolDestroy (release memory)
I think all other stuff is not essential. No need for parent pools,
pools sub-allocation, sibling management, process shared pools, printf
versions that use a pool, and many other features like compatibility
with older versions... No need for that.
Obviously you may have different requirements, in that case use tha APR
library, a fine piece of software
jacob
I am not an IUT student, and I do not have a question, but I have some
answers.
The standard memory allocation strategy of C is to keep track of each
and every piece of RAM. This is an incredibly error prone activity, as
proved by the countless memory allocation bugs that appear in code built
using that strategy.
Another strategy, and the one that I have been proposing here since some
years, is to use the garbage collector and get rid of most problems.
There is an intermediate strategy however, based on pools of memory.
Normally you have a set of related allocations, that can be done from a
memory pool, that is released in a single call when the module that uses
the pool is finished or when the activity associated with the pool is
finished.
A pool, for instance, is handy for a hash table with variable length
keys and variable lengths objects. When the hash table is destroyed, all
the memory that it required can be freed with a single call to pool destroy.
Many other applications are possible. Normally, all big applications are
built with modules that are more or less independent and could benefit
from pooled allocation. In a database application all memory used by one
query can be pooled and released when the query is done.
An example of pool management is in the Apache Runtime (APR) library.
There, the module apr_pools.c proposes a sophisticated interface for
pooled memory management. That library can be downloaded at no cost,
and its license is quite liberal. I adapted some of the code for the
container library, reducing the size of the module to just 1K (1076
bytes when compiled with lcc-win) from around 40K of the original.
The reduced interface proposes
newPool (create a pool)
PoolAlloc (allocate)
PoolDestroy (release memory)
I think all other stuff is not essential. No need for parent pools,
pools sub-allocation, sibling management, process shared pools, printf
versions that use a pool, and many other features like compatibility
with older versions... No need for that.
Obviously you may have different requirements, in that case use tha APR
library, a fine piece of software
jacob