On 24 Dec 2003 20:18:04 -0800,
tron.thomas@verizon.net (Tron Thomas) wrote:
[color=blue]
>powermatic66.removethis@yahoo.com (Bob Summers) wrote in message news:<3fea12cc.23041421@news.concentric.net>...[color=green]
>> Instead of asking for opinions, why not do some benchmarks? One
>> good benchmark trumps 1,000 opinions. Especially when the performance
>> of whole application is concerned.
>>
>> See <http://www.microquill.com> for some tips on benchmarking
>> heap allocators. They also sell a very good heap allocator.
>>
>> Are you really sure that heap fragmentation is a big issue? I'd be
>> interested in seeing some data, if you have it.
>>
>> Don't forget that the reason for minimizing new/delete calls
>> is because they take time and they can cause a great deal of
>> contention in multi-threaded servers.
>>
>> Slab allocators sound good, though I've never measured
>> one. See for example:
>> <http://srl.cs.jhu.edu/courses/600.418/SlabAllocator.pdf>
>>
>> A very quick once over (well it was more like a glance) of
>> the code gave me the impression that its a naive memory allocator;
>> though it's entirely possible that I missed something.
>>
>> Walking a linked list of blocks is likely to cache unfriendly.
>> I didn't even see the simple stuff like multiple pools for different
>> sizes of block, let alone, processor or thread specific pools.
>>
>> And where do you deal with the minimum alignment?
>>
>> You might also want to check out the Hoard allocator
>> at <www.hoard.org>. I tested it against the Microquil
>> allocator a few years ago and the Microquill allocator,
>> SmartHeap, was much faster in my application.
>>
>> Bob S[/color]
>
>The comments I listed in my post concerning fragmentation were based
>on criticism given by a company where I applied for a programming
>position. I sent them the code from some projects I had done and they
>were concerned about the way I handled memory in one of my programs,
>even though they had never run the program and done any benchmarks
>against it.
>
>The program is not that complicated and seems to run fine as it is. I
>thought there would be value in dealing with the criticism they
>offered in case someone else should review the code and come to a
>similar conclusion. Plus, it would be a good learning experience.
>
>I believe I have a strategy that will improve things. I will also
>look at the links you suggested.
>
>What exactly is minium alignment and how is it usually dealt with?[/color]
On most (all?) RISC machines, addresses of primitive types have to
be a multiple of the size of the item, i.e. the address of a
4 byte int has be a multiple of the integer size. Even platforms
that allow unaligned loads and stores will generally run much faster
with aligned loads. Imagine what can happen when you try to load an
int that spans pages. Both sides of the int can generate their own
TLB miss, cache miss and pagefault.
That means that data structures must be aligned so that all of their
component parts are correctly aligned. The compiler will assume that
the heap allocator will use some minimum alignment. I think
most 32 bit machines will want 64 bits to be the minimal alignment.
You have to understand how your CPU does addressing to know what
the right value is. In some applications, you'd profit by spending
some space to get cache line alignment, i.e. 32 or 64 bytes with
64 bytes becoming more common.
I think that most allocators will just know what alignement the OS
gives them when they request a chunk of memory. I think that this
will be page aligned on all platforms. If not, it's pretty simple
to check what the actual alignment is as long as you know what the
internals of a pointer look like. Then the allocator will
allocate in chunks that are multiples of the minimum alignment.
I've spent quite a bit of time working in integer code performance
in the last 10 years or so and I can truthfully say that I've never
worried about heap fragmentation. Heap allocation and deallocation
I've worried about constantly but never fragmentation. It's possible
that the person that interviewed you didn't know what they were
talking about or the two of you miscommunicated. It's also
possible that they were right. Without more context, I can't come
up with a reasonable explanation for the criticism. Was this for
an embedded system or numeric application? Did your interviewer
mean pointer chasing or other skipping around in memory instead
of fragmentation?
Bob S