Re: Efficient memory allocation
- From: "Chris Becke" <chris.becke@xxxxxxxxx>
- Date: Wed, 28 Nov 2007 11:17:58 +0200
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.
.
- Follow-Ups:
- Re: Efficient memory allocation
- From: Ben Voigt [C++ MVP]
- Re: Efficient memory allocation
- From: Kürşat
- Re: Efficient memory allocation
- References:
- Efficient memory allocation
- From: Kürşat
- Efficient memory allocation
- Prev by Date: Efficient memory allocation
- Next by Date: Re: fgets() equivalent?
- Previous by thread: Efficient memory allocation
- Next by thread: Re: Efficient memory allocation
- Index(es):
Relevant Pages
|
Loading