"Vladimir Panteleev" <[email protected]> wrote in message 
news:[email protected]...
> On Thu, 15 Jul 2010 11:03:57 +0300, JimBob <[email protected]> wrote:
>
>> VirtualAlloc returns chunks that have 'dwAllocationGranularity' 
>> granularity,
>> which is 64K on every Windows OS I've used. So allocating a page, 4K, 
>> will
>> actualy get you 64K.
>>
>> So using VirtualAlloc as a replacement for malloc is very wasteful unless
>> the allocations are larger that 64K.
>>
>> You might want to look at HeapCreate and it's siblings. (on windows 
>> anyway)
>
> dwAllocationGranularity only controls the granularity of the allocation 
> address, but not of the allocation size. A simple program that calls 
> VirtualAlloc 16384 times uses up 1 GB of the address space, but only 64 MB 
> of actual memory. So, while it is a waste of address space, it's not a 
> waste of system memory.

Appologies, msdn says you're right.

Which sucks cause I recently rewrote a bunch of code because of that 
misunderstanding.

Thanks.



Reply via email to