-
How to reserve RAM for my program
Hi
Can anyone offer advice on how to force the system to put aside say 10Mb
RAM as working area for data that my VB program is generating at runtime?
I want to guarantee that the data is not swapped to the swapfile and that
the program does not crash when I try to use more RAM than there is free.
Can I somehow get some of the other data being used by windows or other programs
to swap out and give me more space?
Thanks in advance
Chris
-
Re: How to reserve RAM for my program
ChrisA -
Crikey! What do you want to do this for? The only way that I can think of
that might do this is by allocating memory using the Win32 API memory
functions, and then using the VirtualLock function to lock it into physical
RAM.
However, you'd better look at the notes on this function:
---------------
Remarks
All pages in the specified region must be committed. Memory protected with
the PAGE_NOACCESS flag cannot be locked.
[important]
Locking pages into memory may degrade the performance of the system by
reducing the available RAM and forcing the system to swap out other critical
pages to the paging file. By default, a process can lock a maximum of 30
pages. The default limit is intentionally small to avoid severe performance
degradation. Applications that need to lock larger numbers of pages must
first call the SetProcessWorkingSetSize function to increase their minimum
and maximum working set sizes. The maximum number of pages that a process
can lock is equal to the number of pages in its minimum working set minus a
small overhead.
Pages that a process has locked remain resident even when the process is
idle for extended periods.
To unlock a region of locked pages, use the VirtualUnlock function. Locked
pages are automatically unlocked when the process terminates.
This function is not like the GlobalLock or LocalLock function in that it
does not increment a lock count and translate a handle into a pointer. There
is no lock count for virtual pages, so multiple calls to the VirtualUnlock
function are never required to unlock a region of pages.
[very important]
Windows 95/98: The VirtualLock function is implemented as a stub that has no
effect and always returns a nonzero value.
---------------
_Complete_Guess_Here_, but you could use the VirtualProtect function to do a
similar thing, if you are doing this in 95/98.
--
Mark Alexander Bertenshaw
Programmer/Analyst
PrimeResponse
Brentford
UK
"ChrisA" <cgandrew@geocities.com> wrote in message
news:39fb9e07$1@news.devx.com...
>
> Hi
>
> Can anyone offer advice on how to force the system to put aside say 10Mb
> RAM as working area for data that my VB program is generating at runtime?
> I want to guarantee that the data is not swapped to the swapfile and that
> the program does not crash when I try to use more RAM than there is free.
> Can I somehow get some of the other data being used by windows or other
programs
> to swap out and give me more space?
>
> Thanks in advance
> Chris
-
Re: How to reserve RAM for my program
Hi Chris,
> Can anyone offer advice on how to force the system to put aside say 10Mb
> RAM as working area for data that my VB program is generating at runtime?
> I want to guarantee that the data is not swapped to the swapfile and that
> the program does not crash when I try to use more RAM than there is free.
There is no generic way to reserve physical memory or even determine
available memory that will work reliably across all current versions of
Windows. It is, however, quite possible to design programs that do not
'crash' by trying to use too much memory, and I'd recommend you focus on
that strategy.
For example, I can hardly imagine an application that needs true random
access to 10MB of data. Depending on what you're trying to do, you'll most
likely find that working with a 'window' consisting of a much smaller amount
of memory (something reasonable, like 64-256KB) to do your
calculations/processing on and keeping the rest of the data on disk (to be
loaded/saved on demand) will work out mich better, or that a similar
approach with multiple small windows (like 10 chunks of 16-64KB each...)
will do the job.
I've used this approach successfully with several apps doing non-trivial
matrix calculations, and though there is a performance hit as well as
additional development work, your apps will scale a lot better, without
randomly running out of memory when confronted with a dataset that is 'too
complex'...
'//mdb
-
Re: How to reserve RAM for my program
Tricks, Components
"michiel de bruijn" <mdb+devx@x42.net> wrote in message
news:39fcb5a5$1@news.devx.com...
> Hi Chris,
> For example, I can hardly imagine an application that needs true random
> access to 10MB of data. Depending on what you're trying to do, you'll most
Oh yeah. How about mapping applications. A map of even a small county can
easily take up 30-40 mb
> likely find that working with a 'window' consisting of a much smaller
amount
> of memory (something reasonable, like 64-256KB) to do your
> calculations/processing on and keeping the rest of the data on disk (to be
> loaded/saved on demand) will work out mich better, or that a similar
> approach with multiple small windows (like 10 chunks of 16-64KB each...)
> will do the job.
>
> I've used this approach successfully with several apps doing non-trivial
> matrix calculations, and though there is a performance hit as well as
> additional development work, your apps will scale a lot better, without
> randomly running out of memory when confronted with a dataset that is 'too
> complex'...
>
> '//mdb
>
>
>
-
Re: How to reserve RAM for my program
The usual result of doing what you want is to degrade system performance,
decrease system reliability and generally get your app a bad name.
If you absolutely must go this way (for which there is no rational reason),
I recommend studying the lengthy discussion in Richter's book (MS Press). He
will also show better ways of improving performance that don't mess with the
Windows swap algorithm.
"ChrisA" <cgandrew@geocities.com> wrote in message
news:39fb9e07$1@news.devx.com...
>
> Hi
>
> Can anyone offer advice on how to force the system to put aside say 10Mb
> RAM as working area for data that my VB program is generating at runtime?
> I want to guarantee that the data is not swapped to the swapfile and that
> the program does not crash when I try to use more RAM than there is free.
> Can I somehow get some of the other data being used by windows or other
programs
> to swap out and give me more space?
>
> Thanks in advance
> Chris
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks