Re: Heap fragmentation
- From: Nobody Here <nobby@xxxxxxxxxxxxxxx>
- Date: 13 Apr 2006 09:31:02 GMT
Thomas Ruschival <Thomas@xxxxxxxxxxxx> wrote:
Hi groups,
in University I learnt about heap fragmentation, and I wanted to measure
it by some example code written in C running linux. Strangely I
couldn't measure any timing differences.
What I do is allocate 500 000 chunks of memory all randomly sized between
1 and 1234 bytes and place them in an array of fixed size. This action is
measured. Then I free each element of the array again.
over this procedure I cycle a hundred times.
After the first cycle I expect to have a horribly fragmented heap but
_all_ cycles take the same time to execute plus minus 4 milliseconds
which I think come form scheduling.
I there any wrong in my assumption or measurement, or is there a fancy
low fragmentation heap management in Linux glibc?
You're allocating everything at once and then deallocating everything at
once. Chances are good that the same memory us used each time. If you
have (for example) a megabyte of allocation, it's likely to be in
contiguous (virtual) memory in the absence of any other activity. You then
free all of that, and chances are that the next time you allocate you're
going to reuse the nice big contiguous memory area you're just freed up.
You should allocate and deallocate randomly as well. Try something like
for (lot os times)
- allocate a random chunk at a random index into your array
- free a chunk at another random location in your array if it's
been allocated
That way you're randomising the allocation and deallocation order
of chunks of memory, and your heap will quickly fragment.
Hmmm, having said that it'll probably eventually settle down to some
pattern in memory that's based on the maximum or average size of your
allocated chunks.
--
Nobby Anderson
.
- Follow-Ups:
- Re: Heap fragmentation
- From: Thomas Ruschival
- Re: Heap fragmentation
- References:
- Heap fragmentation
- From: Thomas Ruschival
- Heap fragmentation
- Prev by Date: Heap fragmentation
- Next by Date: TDP editor with RTRT eval version
- Previous by thread: Heap fragmentation
- Next by thread: Re: Heap fragmentation
- Index(es):
Relevant Pages
|