data.d
Vladimir Panteleev
vladimir at thecybershadow.net
Thu Jul 15 02:03:27 PDT 2010
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.
I think that using heaps of any kind defeats part of this module's
purpose, for the reason that due to heap fragmentation it is not possible
to return memory to the OS directly (which is only possible to do in whole
pages). There is also a small performance cost involved with using heaps.
--
Best regards,
Vladimir mailto:vladimir at thecybershadow.net
More information about the Digitalmars-d-announce
mailing list