G
glen herrmannsfeldt
(snip, someone wrote)
One reason not to is the poor peformance of virtual memory systems.
I know some put at least some of the data elsewhere for better
virtual memory reasons. If you follow a linked list through the
beginning of each allocated block, you have to page in that block.
I know some do it differently, but I don't remember how much.
You could put a linked list somewhere else, and a pointer to a
link in the list before each block, to make free fast.
A hash table for free should also be pretty fast.
I suppose, but you could do that even without the data before
each block.
One that I have wondered about is web browsers and the data that
they keep for each tab or window. Many perform poorly, doing a lot
of paging, as their memory use gets big.
-- glen
(snip)
ISTM that most malloc implementations place their memory managment nodes
between the allocated memory spaces which would cause the alignment creep
you mention. It is also potentially fragile because 1) those spaces cannot
be protected, and 2) a pointer going just beyond where it should could lead
to corruption of a node.
One reason not to is the poor peformance of virtual memory systems.
I came up with an idea for a memory allocator which stores all of its
metadata elsewhere (though I am not looking at impementing that just now).
It is a little more complex and wouldn't have such good free() performance.
free() normally just has to offset the pointer it is passed in order to find
the node but if not stored relative to the start of the allocated memory
space the node would need to be found. Storing the node-type data elsewhere,
though, does buy you quite a bit: greater security, the alignments you want
and often faster scanning for malloc to find space.
I know some put at least some of the data elsewhere for better
virtual memory reasons. If you follow a linked list through the
beginning of each allocated block, you have to page in that block.
I know some do it differently, but I don't remember how much.
You could put a linked list somewhere else, and a pointer to a
link in the list before each block, to make free fast.
A hash table for free should also be pretty fast.
Don't forget that alignment creep can be a good thing if it ends up
offsetting cache lines that are used together so perfect alignment can
sometimes be a bad thing - less of a problem now with CPUs which have
many-way caches.
I suppose, but you could do that even without the data before
each block.
One that I have wondered about is web browsers and the data that
they keep for each tab or window. Many perform poorly, doing a lot
of paging, as their memory use gets big.
-- glen