Re: Efficient memory allocation



Chris,
If I use 'placement new' to construct an object in the pre-allocated memory
(allocated by VirtualAlloc()) and then delete that object, what happens to
memory space occupied by that object? Is it still valid?

"Chris Becke" <chris.becke@xxxxxxxxx> wrote in message
news:%23b0vX$ZMIHA.5208@xxxxxxxxxxxxxxxxxxxxxxx
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: Whats the difference between the heap and the freestore?
    ... > In general, when discussing dynamically allocated memory, I hear people ... As of a couple of days ago, I though the heap ... pool of memory from which a C++ program allocates storage for dynamic ...
    (comp.lang.cpp)
  • Re: Efficient memory allocation
    ... 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: 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: simplest dynamic memory manager / allocator
    ... You might find that 4tH doesn't reserve much memory for dynamic ... memory is allocated at the heap, ... 768 allocates 64 bytes. ... Every fragment is represented by a cell in the HAT. ...
    (comp.lang.forth)
  • 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)