Re: Efficient memory allocation



1. Call VirtualAlloc once - far easier for you to manage a single object
than 3000.

2. VirtualAlloc will allocat the memory only. to construct your objects you
would need to use 'placement new'.
http://www.google.com/search?q=placement+new for more info on that.

3. VirtualAlloc allocates 4K pages of memory at a time. HeapAlloc allocates
dword aligned memory thats is an arbitrary size - by subdividing memory it
internally allocates using VirtualAlloc.

4. If you are writing a service or application prone to causing heap
fragmentation then you probably should use the low fragmentation heap.

"Kürþat" <xx@xxxxxx> wrote in message
news:eeQUKuZMIHA.5208@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

In my IOCP based server application I want to pre-allocate a certain
amount of memory for later use. Preallocated memory will be used with
overlapped I/O operations and be locked as long as I/O is pending. Using
VirtualAlloc () and page aligned allocation is efficient way to allocate
memory as long as I research.

But I can't figure out some points :

1- Suppose I want to preallocate memory for 3000 OVERLAPPED derived
objects.I will later use those objects with overlapped I/O and IOCP
framework. If page size is 4K, I need 3000 * 4K = 12000K of memory.Should
I allocate whole 12000K making one VirtualAlloc () call or call
VirtualAlloc () 3000 times?

2- Is it right to use VirtualAlloc () and VirtualFree () with objects? Can
they create and destroy objects (are c.tor and d.tor invoked?)

3- What is the difference between HeapAlloc-Free and VirtualAlloc-Free?

4- What is the Low-fragmentation Heap? Should I use this heap in my server
instead of normal memory?

Thanks in advance.



.



Relevant Pages

  • Re: VirtualAlloc fails (ERROR_NOT_ENOUGH_MEMORY) on 22MB request; I compute 420MB available...
    ... the point that a call to VirtualAlloc was failing. ... what the process heap indicates as freely available ... memory won't matter when trying to VirtualAlloc for example a 22 meg ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Efficient memory allocation
    ... VirtualAlloc allocates 4K pages of memory at a time. ... fragmentation then you probably should use the low fragmentation heap. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: VirtualAlloc or LocalAlloc? Plz Help
    ... VirtualAlloc allocates a section of virtual memory address space. ... some 2GB region whereas LocalAlloc allocates memory from the 32 MB ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Efficient memory allocation
    ... If I use 'placement new' to construct an object in the pre-allocated memory ... VirtualAlloc will allocat the memory only. ... VirtualAlloc allocates 4K pages of memory at a time. ... fragmentation then you probably should use the low fragmentation heap. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: What happened to function _memmax?
    ... My question applies to the current CRT heap, ... > the whole virtual memory, otherwise I would have posted it to an SDK group. ... See also functions like VirtualAlloc. ...
    (microsoft.public.vc.language)

Loading