data.d
Rainer Schuetze
r.sagitario at gmx.de
Thu Jul 15 15:20:07 PDT 2010
Vladimir Panteleev wrote:
> On Thu, 15 Jul 2010 11:03:57 +0300, JimBob <jim at bob.com> 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.
In a 32-bit process, the waste of address space is sometimes more
critical nowadays. There is only 2GB virtual memory available (3GB with
some tweaks), and with the example above, VirtualAlloc fails well before
allocating 128 MB.
More information about the Digitalmars-d-announce
mailing list