S
Stephen Sprunk
Joris Adriaenssens said:Is it the operating-system that is responsible to remember the size of
that piece of memory ?
In that case, when I build a large linked-list by allocating memory
for each node, I get a lot of overhead in the operating system. Is
this right ? or is this implementation-specific or operating-system
specific ? (FAQ q7.26 says that the implementation 'remembers' the
size. Does this mean that every implementation may do it in his own
way ? )
That's implementation-defined, though there are only a few obvious and
efficient ways to meet the requirements.
If the computer has to remember for each single allocation the size of
the allocated block, is it better than, to allocate a bigger piece of
memory and keep track of the use of it within the program, when I try
to create a linked-list or a binary tree or something like that ?
That will depend on whether your code is more or less efficient than the
malloc/free provided by your implementation. As a rule of thumb, use what
the standard library provides unless you determine (through profiling) that
it does not meet your needs. malloc is one of the most highly-tuned
functions in existence, so odds are you'll only be able to improve on it in
corner cases if at all. More importantly, your replacement is substantially
more likely to have bugs, and the risk often outweighs the potential
benefits unless you're very experienced at writing memory management code.
S