News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Timing large file reads

Started by KeepingRealBusy, May 01, 2010, 09:01:03 PM

Previous topic - Next topic

redskull

Quote from: jj2007 on June 14, 2010, 12:21:21 PM
Plain HeapAlloc does not zero memory. However, if you request more than 126 pages, i.e. more than about 520,000 bytes, Windows switches to VirtualAlloc and zeroes memory.

The heap function do zero memory, in a way; all pages come back from the memory manager zeroed out, and then the heap itself fills it with magic numbers so it can test for corruption.  Even if you only HeapAlloc a couple bytes, it still has to VirtualAlloc an entire page at a time to your process, so there's nothing stopping you from reading or writing to locations your haven't officially allocated, and causing bugs  So really, HeapAllocs are twice as slow, because it not only has to be zeroed from the memory manager, but then filled with the check characters from the heap.  As to why the Heap doesn't do this for large allocations...?  It seems to the tipping point of when it runs out of space in the intial heap, and has to allocate a new one somewhere else in memory

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

jj2007

You are right - HeapAlloc returns BAAD F00D...

By the way, we covered that ad nauseam in this thread; which showed (not surprisingly) that HeapAlloc was considerably faster than VirtualAlloc for repeated small allocations.