Performance using Static Buffer vs Dynamic Buffer



I wrote a simple application to use the Crypto++ MD5 Algorith and I
was surprised to find that it takes much longer to calculate the
checksum of a file if I allocate the buffer on the heap vs a static
buffer.

I wrote two functions with the only difference being one is:

static BYTE buffer[1024*1024];
....
process MD5
....

and the other one is:

PBYTE buffer = new BYTE[1024*1024];
....
process MD5
....
delete []buffer;

On a particular data file which is about 500 MB it took 12 seconds for
the calculation using the static buffer and 80 seconds for the
calculation using the dynamic buffer.

To make sure it wasnt a disk caching or fragmentation issue I made a
scond copy of the file and performed the test twice swapping which
file I used for the static vs dnamic test and the results were
consistent.

The machine I'm using has 3 GB memory so I don't think that that is a
limitation.

This was totally unexpected to me. Any thoughts?

.



Relevant Pages