Re: Memory fragmentation
On 2007-08-29 12:27, cppquester@googlemail.com wrote:
Recently I ask here about custom new and delete.
There some people stated, that memory fragemtation
might be avoided by this.
Just to get this clear:
As long as I have enough physical memory installed,
fragementation does not matter at all for the performance, does it?
Some memory might be wasted, but does this matter for the
performance in any way? (on a typical implementation on
a x86 workstation (gcc, vc, ...))
The following is totally off topic for this group since it deals with
the hardware.
If the data needed by the program is located all over the place it can
have negative impact on the performance due to caching. There are two
problems, the first is that the CPU works by the principle of locality
of reference, meaning that a program usually tends to work on data with
addresses close to each other. This means that the CPU can speculate on
what address you'll be accessing next and load them at the same time. IF
this fails it means that 1) it has spent time to load data into cache
that you don't need, and 2) that it has to load some other data into the
cache.
A second problem is that two non-contiguous addresses can map to the
same cache-line, which means that the CPU might have to pull some data
back and forth between cache and RAM while working. This is probably not
as common since the CPU guys have some cleaver techniques to prevent
this from happening.
If you want to be a good programmer you really need at least a basic
understanding of how the hardware works, Patterson and Hennessy have
written good books on the topic.
--
Erik Wikstr?m