🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.programmer
Article #2096

Re: Watcom and Available Memory

#2096
From: Jeff Petersen
Date: Fri, 19 Jan 1996 16:59
45 lines
2979 bytes
> Hi.  I have Watcom C++ v10 and I need a way to find out how much free
>RAM is left available to allocate.  I've played with _heapwalk() and
>memaval etc and they only report about 3k available.  I have 32mb of
>RAM.  I'm doing this with DOS/4GW and wpp386.  If anyone knows a way
>of reporting the entire FREE RAM space I'd be greatful if they were to
>share it with me.  Preferably I'd like to know if there is a standard
>way of finding the entire free "core" area under any C or C++ system.
>I there is none i think it's a gapping hole in the standard.

Better get used to not knowing; it is a bad habit to get into.  You may be 
able to find a way to get the system to report that it has 10mb free, but if 
you were to try and allocate 10 - 1mb chunks something would probably fail due 
to fragmentation.  Also, newer operating systems like NT virtualize stuff 
whether you like it or not.  I wrote a sort program once that wanted to use 
all available memory (under NT) and at any given time, a large portion of the 
memory is in use, but can easily be freed up by either throwing it away 
(cached stuff) or swapping it to disk.  You sort of need to ask yourself where 
the line is when you start forcing the OS to swap stuff out that it will need 
real soon or maybe even swapping your sort buffers out (largely defeating the 
purpose).  What happens when the user opens another application after your 
application has taken everything -- you start swapping again.

In the case of the sort program, I asked the system how much total real memory 
there was (32mb and this case) and told my sort program (which is designed to 
have primary control of the machine while being ran) to take TOTAL - 8mb (or 
24mb).

All of that said, under DOS4GW (with VM off) I wrote a little function that 
tried to allocate 64mb and then kept shrinking the request (256k at a 
time) until it succeeded.  It then freed the chunk and told me what it could 
get.  This does not give you total available, but does give you the largest 
chunk you might be able to get.  If you do it early in the program and 
remember the number, it will give you a pretty good indication of how much you 
have to work with total (leave a little slack for fragmentation (particularly 
if you are doing large allocations)).

BTW, if anybody is doing large allocations (>512k) under WindowsNT I have an 
interesting bug that you might want to know about, if anybody is interested 
drop me a note.



Jeff Petersen
Artificial Software
jeffp@itsnet.com
Technical Details
Message-ID: <4dokk1$stk@itchy.itsnet.com>
Path: arc1-ca.pugleaf.net!news.itsnet.com!ip47
References: <4do475$1da@oznet07.ozemail.com.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.itsnet.com!ip47
From: jeffp@itsnet.com (Jeff Petersen)
Newsgroups: rec.games.programmer,comp.lang.c,comp.lang.c++
Subject: Re: Watcom and Available Memory
Date: Fri, 19 Jan 96 16:59:58 GMT
Organization: Artificial Software
Message-ID: <4dokk1$stk@itchy.itsnet.com>
References: <4do475$1da@oznet07.ozemail.com.au>
NNTP-Posting-Host: ip47.itsnet.com
X-Newsreader: News Xpress Version 1.0 Beta #4