Liberty BASIC Community Forum
« memory availability »

Welcome Guest. Please Login or Register.
Feb 22nd, 2018, 12:35pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: memory availability  (Read 940 times)
richard peeters
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 43
xx memory availability
« Thread started on: Feb 26th, 2003, 11:55am »

How can we determine the memory available for a program?

A DLL call in LibSQL returns pointers. I want to know the size of memory I can set aside for that without crashing the program.


Richard
User IP Logged

Dennis
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 299
xx Re: memory availability
« Reply #1 on: Feb 26th, 2003, 2:13pm »

I'm no expert at this but a couple of things come to mind. If you know the amount of memory you need why not request it with GlobalAlloc? If the function returns NULL there isn't enough memory, otherwise it allocates it and returns the handle. The other one is to call GlobalMemoryStatus, although that could trip you up since the amount could change before you could allocate it.

By any chance is the DLL call returning pointers to arrays of records? If so I would think the memory would already be allocated.(?)

Dennis
User IP Logged

Life is what happens while you're making other plans.

The LibertyBelle http://www.syberden.net/libertybelle

SD DataGrid http://www.syberden.net
richard peeters
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 43
xx Re: memory availability
« Reply #2 on: Feb 27th, 2003, 01:23am »

Hi David,

I don't know in advance how much memory I will need since the size of the returned table changes everytime.
What I would like to do is check the available memory at the beginning of the program and reserve as much memory as possible.
BTW I don't know anything about API calls.

Richard
User IP Logged

CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2834
xx Re: memory availability
« Reply #3 on: Feb 27th, 2003, 06:23am »

on Feb 26th, 2003, 11:55am, richard peeters wrote:
How can we determine the memory available for a program?

A DLL call in LibSQL returns pointers. I want to know the size of memory I can set aside for that without crashing the program.


Richard


Hi Richard,

Liberty BASIC has a 70MB memory limit. Typically LB consumes about 4MB of RAM when it is started, leaving you with theoretically 66MB. I'm not sure what the format is for the LibSQL data structures the call in question uses, but for a collection of 32-bit pointers, each one would take 4 bytes.

Are you operating on really huge query result sets?

-Carl
User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
richard peeters
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 43
xx Re: memory availability
« Reply #4 on: Feb 27th, 2003, 07:33am »

Carl wrote:
Quote:
Liberty BASIC has a 70MB memory limit. Typically LB consumes about 4MB of RAM when it is started, leaving you with theoretically 66MB. I'm not sure what the format is for the LibSQL data structures the call in question uses, but for a collection of 32-bit pointers, each one would take 4 bytes.
Are you operating on really huge query result sets?



Hi Carl,

With a machine having 128 or even 256 Mbytes of RAM one can use the 66 Mbytes. But what if you have only 32 or even 16 Mbytes??
I think the old basics had a MEM statement returning the amount of available memory. Can it be done with an API call in LB?

I am reserving a certain amount, indeed 4 bytes per pointer. But in SQL the returned tables (for example after a join) can become huge. My program checks that the table is not to big, but I would like to use the available memory to it maximum. Therefore I need to know how much is available in the first place.


Richard
User IP Logged

Dennis
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 299
xx Re: memory availability
« Reply #5 on: Feb 27th, 2003, 08:03am »

Richard,

Will this work for you?

Dennis
------------
struct MEMORYSTATUS,_
dwLength as ulong,_
dwMemoryLoad as ulong,_
dwTotalPhys as ulong,_
dwAvailPhys as ulong,_
dwTotalPageFile as ulong,_
dwAvailPageFile as ulong,_
dwTotalVirtual as ulong,_
dwAvailVirtual as ulong

MEMORYSTATUS.dwLength.struct = len(MEMORYSTATUS.struct)

calldll #kernel32, "GlobalMemoryStatus", MEMORYSTATUS as struct, r as void

print MEMORYSTATUS.dwMemoryLoad.struct
print MEMORYSTATUS.dwTotalPhys.struct
print MEMORYSTATUS.dwAvailPhys.struct
print MEMORYSTATUS.dwTotalPageFile.struct
print MEMORYSTATUS.dwAvailPageFile.struct
print MEMORYSTATUS.dwAvailVirtual.struct

User IP Logged

Life is what happens while you're making other plans.

The LibertyBelle http://www.syberden.net/libertybelle

SD DataGrid http://www.syberden.net
richard peeters
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 43
xx Re: memory availability
« Reply #6 on: Feb 27th, 2003, 09:09am »

Hi Dennis,

Thanks for your reply. On a 32Mbytes machine your code gives me the following output:

100
32993280
53248
1779728384
1689403392
2026635264

Which one do I have to use and how to interprete it??

Richard
User IP Logged

Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14923
xx Re: memory availability
« Reply #7 on: Feb 27th, 2003, 09:13am »

The following came from the Borland SDK helpfile. A link is available on my api page.

http://alyce.hytext.com/

Code:
dwLength

Indicates the size of the structure. The calling process should set this member prior to calling GlobalMemoryStatus. 

dwMemoryLoad

Specifies a number between 0 and 100 that gives a general idea of current memory utilization, in which 0 indicates no memory use and 100 indicates full memory use. 

dwTotalPhys

Indicates the total number of bytes of physical memory. 

dwAvailPhys

Indicates the number of bytes of physical memory available. 

dwTotalPageFile

Indicates the total number of bytes that can be stored in the paging file. Note that this number does not represent the actual physical size of the paging file on disk. 

dwAvailPageFile

Indicates the number of bytes available in the paging file. 

dwTotalVirtual

Indicates the total number of bytes that can be described in the user mode portion of the virtual address space of the calling process. 

dwAvailVirtual

Indicates the number of bytes of unreserved and uncommitted memory in the user mode portion of the virtual address space of the calling process.  
User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


Alyce's Restaurant
for Liberty BASIC code, tools and references
Dennis
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 299
xx Re: memory availability
« Reply #8 on: Feb 27th, 2003, 10:27am »

Quote:
Which one do I have to use and how to interprete it??


Not exactly sure, dwAvailPhys + dwAvailPageFile looks like it would give the total memory available at the moment. Maybe someone who knows for sure will chime in here.

Dennis





User IP Logged

Life is what happens while you're making other plans.

The LibertyBelle http://www.syberden.net/libertybelle

SD DataGrid http://www.syberden.net
CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2834
xx Re: memory availability
« Reply #9 on: Feb 27th, 2003, 12:43pm »

on Feb 27th, 2003, 07:33am, richard peeters wrote:
Carl wrote:


Hi Carl,

With a machine having 128 or even 256 Mbytes of RAM one can use the 66 Mbytes. But what if you have only 32 or even 16 Mbytes??


Well, I imagine the answer varies somewhat from one version of Windows to another, but in general once you exhaust the physical RAM, virtual memory kicks in. You would need to read some documentation from Microsoft about this to have a definitive answer.

-Carl
User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
Colin McMurchie
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 226
xx Re: memory availability
« Reply #10 on: Feb 27th, 2003, 3:35pm »

Can I add a comment here? The calls to the SQLite.dll that Richard is using return pointers to strings that represent the fields and records in an sql table. They return the whole table at a time. These are distributed throughout available memory, and released by a later call. They are copied into liberty basic arrays to be accessed, so the memory required is twice the amount needed to contain the whole table. Having said that, just 1mb will contain 500 duplicated 1k records.

The SQLite.dll has recently been upgraded, to allow the programmer to access data a row at a time, rather than a whole table at a time. This may ease the problem. I will try to get this new method to work, but no promises.

Colin McMurchie
User IP Logged

richard peeters
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 43
xx Re: memory availability
« Reply #11 on: Feb 28th, 2003, 02:20am »

Hi Colin,


Have a look at the sourcecode for LibSQL. I eliminated the array you use in your DLL call. This halves the needed memory. I only need the memory for the pointers.

Richard
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls