Virtual Memory question

I’m using VirtualAlloc(NULL, ulCount, MEM_COMMIT, PAGE_READWRITE) to allocate a chunk of memory. I do this over and over and place the allocated memory on a queue. Another thread in my app frees the memory sometime later after is has completed processing the data. I have noticed that the first x times that I call VirtualAlloc() that it is very fast allocating. Once physical memory, however, is filled up with my VirtualAlloc() (and assuming I am outrunning my processing thread), VirtualAlloc() starts taking a very long time allocating memory. Makes sense, since now it is paging to and from the disk due to the fact that physical memory totally allocated.

My question is this. Is there any way to know without timing the VirtualAlloc() operation, that I have exhausted physical memory and the subsequent VirtualAlloc() allocations are going to force/require disk operations? I can do this by timing each VirtualAlloc() operation, but this is pretty subjective. I was wondering if it might be better to write a driver to handle my memory allocations and then use some sequence of calls to signal the application that any further memory allocations will force a disk/paging operation.

Am I in the weeds here?

Thomas “Rick” Tewell
Ligos Corporation


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

IMHO, this is a poor design if it can be avoided. It is more efficient to have a
pool of chunks already allocated during initialization and then use them in a
round-robin fashion. Use semaphore/event objects in your producer/consumer
threads to efficiently block execution as appropriate. Even more effective is the
use of an IO Completion Port to limt access to the pools. This all assumes that
you design can be effectively implemented with a fixed number of pools. Another
advantage is that if you only have a few pools in use, the paging is all but
eliminated completely. Another thing that is important is that you are using the
pools in multiples of PAGE_SIZE for most effectiveness.

Regards,

Paul Bunn, UltraBac.com, 425-644-6000
Microsoft MVP - WindowsNT/2000
http://www.ultrabac.com

-----Original Message-----
From: Thomas “Rick” Tewell [mailto:rick@1394.com]
Sent: Friday, April 20, 2001 5:13 PM
To: NT Developers Interest List
Subject: [ntdev] Virtual Memory question

I’m using VirtualAlloc(NULL, ulCount, MEM_COMMIT, PAGE_READWRITE) to allocate a
chunk of memory. I do this over and over and place the allocated memory on a
queue. Another thread in my app frees the memory sometime later after is has
completed processing the data. I have noticed that the first x times that I call
VirtualAlloc() that it is very fast allocating. Once physical memory, however, is
filled up with my VirtualAlloc() (and assuming I am outrunning my processing
thread), VirtualAlloc() starts taking a very long time allocating memory. Makes
sense, since now it is paging to and from the disk due to the fact that physical
memory totally allocated.

My question is this. Is there any way to know without timing the VirtualAlloc()
operation, that I have exhausted physical memory and the subsequent VirtualAlloc()
allocations are going to force/require disk operations? I can do this by timing
each VirtualAlloc() operation, but this is pretty subjective. I was wondering if
it might be better to write a driver to handle my memory allocations and then use
some sequence of calls to signal the application that any further memory
allocations will force a disk/paging operation.

Am I in the weeds here?


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com