Article View: borland.public.cppbuilder.nativeapi
Article #7550Re: Preventing memory block from swapping to disk
From: Dennis Jones
Date: Wed, 19 Jan 2005 18:36
Date: Wed, 19 Jan 2005 18:36
36 lines
2866 bytes
2866 bytes
"Tumurbaatar S." <nospam_tumur@magicnet.mn> wrote in message news:41ee1494@newsgroups.borland.com... > I need to lock several MB of memory in RAM. I had read some topics > of Win32 Ref, but somethings are not clear for me: > 1. Global/LocalAlloc() with GMEM_FIXED is enough to get a non-swappable > memory block? > 2. Or I need VirtualAlloc() with MEM_COMMIT and VirtualLock()? > 3. Because VirtualLock() can lock only a small portion of memory (30 * 4K), > I have to SetProcessWorkingSetSize(), but how to determine a minimum > working set size for the process? Memory I need + X..., how much more? > 4. The Min/Max heap size values in Project Options | Linker have any > relation to all above I'm talking? > 5. The memory I need to lock, is used to store a large sorted list with > many items in it and new items are constantly added/removed from the list. > Also values of items also changes constantly. "Constantly" means that > I expect up to 1000 requests (for add/remove/change) per second. > Because my program so often access this memory block (whole memory > block, not some portion of it), will system keep it in RAM by default? Jeffrey Richter has a section on this subject in his book, "Advanced Windows." In it, he says you must use VirtualLock/VirtualUnlock, and that you can only lock 30 pages at a time. He also says that the pages are guaranteed to be locked only while the thread that locked them is executing. If the thread is preempted, Windows tries to keep it in memory if it can, but other factors may cause it to swap the pages out to disk until the thread is runnable again, at which time the data is swapped back into memory just before your thread is resumed. One observation he makes is that the OS is very good at determinig the most efficient way to manage paged memory and that you should not try to override it under most circumstances because you may actually get worse performance. Good luck, - Dennis
Technical Details
Message-ID:
<41eea8c0@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41ee1494@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,c5b636ba1001447d X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Dennis Jones" <nospam@bogus.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <41ee1494@newsgroups.borland.com> Subject: Re: Preventing memory block from swapping to disk Date: Wed, 19 Jan 2005 10:36:47 -0800 Lines: 38 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 204.200.27.7 Message-ID: <41eea8c0@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1106159808 204.200.27.7 (19 Jan 2005 10:36:48 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail