Mail Archives: djgpp/2000/09/18/10:01:43
Hiper M.A.R. <hipermar AT mail2 DOT esoterica DOT pt> wrote:
> Incoerent results are given deppending on how memory is malloc or
> realloc:
> a)Using a straight foward malloc
> b)Trying to malloc in 1MB step
> c)Trying to realloc in 1 to 10 MB steps.
They're not really incoherent. The results are different, for the
three modes, but that's not an incoherence, because is no guarantee
whatsoever that they should be equal, to begin with.
What you observe is that heap fragmentation can cause some fraction of
available memory to becomme effectively unreachable to a program, and
the size of the fraction will depend on the allocation strategy.
> a) 124 125
I.e. you have about 124 Megs of RAM available, in principle.
> b) 95 96
Allocation in chunks of 1 Megabyte wastes part of it, because chunk
sizes will be rounded upwards, and some book-keeping overhead is
also needed for malloc() to be able to work.
> c) 1 35 36
> 2 42 44
[...]
> 10 60 70
Realloc()ing 'upwards' is a bad stragety, and it gets worse the
smaller the steps are. That's what this tells you. The reason behind
this is that the free()d blocks from the earlier, small realloc()
calls are not available for re-use as part of larger blocks, later on.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -