🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #6038

Re: How to Make Sure that Buffer use ONLY memory

#6038
From: Bob Gonder
Date: Sun, 12 Jun 2005 17:37
87 lines
4797 bytes
Daniel wrote:

>No, i haven't tried that yet becouse i'm just starting now to
>build my application, BUT, i know that it whould have to do LOT
>of calculations, and i estimate that it will take it several
>months of continuous operating to get the final results,

>>Have you investigated the VirtualLock functions that Liz mentioned?
>
>Yes i read yesterday a lot about this subject, but i'm still 
>not sure if i understand how to use this method, i'm also not
>sure if it will work on my Windows-XP with my builder 4.0

Wy not?
See "Requirements/Client" at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/virtualalloc.asp

>>How much memory do you realy need? A couple MB, no problem.
>
>I need AS MUCH AS POSSIBLE, my computer have 256 MB, if it's 
>possible i want to use ALL the 256 MB.

That's still pretty vague.
How big is the data set?
Assume you had a MegaTerra Byte of RAM.
How much would you need?

On a 256MB computer, you will have maybe 100MB usable.
That 100MB must contain your program, all dlls and your data.
Not really all that much will be available.

>>Have you heard of a method called double buffering?
>
>I heard, but i have no idea how does it relate to my issue, if
>possible please explain how can it help me here.

If your calculating proceeds in an orderly manner through the data
(sequential, or nearly so rather than truely random), then you might
have 2 threads. 1 thread calculating and updating the data, the other
thread anticipating the data about-to-be-needed, and reading that off
disk (Reading in chunks is, of course, better that per-double)
Double-buffering, in that thread 1 is reading/calculating/updating one
buffer while thread 2 is saving/retrieving the next bit.

>>You might also want to check out CreateFileMapping and MapViewOfFile
>>especially if your calculations are fairly linear.
>
>The size of my buffer (or my buffers) will be constant and will
>not be change during the running (i hope...) if that's what 
>you mean. Please tell me a little about 'CreateFileMapping' 
>and 'MapViewOfFile', How can it help me with my memory 
>problem? (i used 'CreateFileMapping' in the past to create 
>share memory between 2 applications but i don't know how to 
>force it to create that memory on the real memory and not on
>the hard-disk).

It's not just for memory sharing.
Use it for it's intended purpose: Virtual Memory.
It eliminates the file reading/writing from your code.
The O/S takes care of that.

>>>So How do i detect what is the largest size of buffer that i can
>>>use that will not use the hard drive space? i guess that it can 
>>>be change from one running to another depends on the amount of
>>>memory which is in used at that moment.
>>
>>See VirtualQuerry and VirtualQuerryEx as well as GetSystemInfo
>>and GetProcessWorkingSetSize
>
>I'll check it thanks.
>
>You gave me many methods here, and i'm realy confused now, 
>let's say that YOU had to do that, in which of all this 
>methods would you select?

That really depends on how Big is the Data Set??
If it is small enough for FileMapping, I'd likely go with that as it
would be simplest.
If I was still concerned about the speed, I'd add a visible progress
device that updates less than 1 per second (visual updates are slow)
so I could time it.
Then add VirtualAlloc code (more complicated) and retest.
As for disk reads...if you can get a minute of calculation out of a 1
second disk read, i wouldn't sweat it as you are talking 1/2 day of
disk delay per month of calculation.
If you are running on a laptop with a slow drive, consider using a
desktop, or adding an external USB disk drive.
Technical Details
Message-ID: <kdqoa11nmfhki6qcdmue2vt9poh235d958@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <42ab3793$1@newsgroups.borland.com> <gjmna117s71qnpihpbtg7sqmbbvaob90q6@4ax.com> <42abfa21$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,93efc3d53d15c3e4
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: How to Make Sure that Buffer use ONLY memory 
Date: Sun, 12 Jun 2005 10:37:46 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <kdqoa11nmfhki6qcdmue2vt9poh235d958@4ax.com>
References: <42ab3793$1@newsgroups.borland.com> <gjmna117s71qnpihpbtg7sqmbbvaob90q6@4ax.com> <42abfa21$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.77.201.161
X-Trace: newsgroups.borland.com 1118597864 67.77.201.161 (12 Jun 2005 10:37:44 -0700)
Lines: 91
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail