Article View: comp.os.msdos.programmer
Article #5454Re: Available dynamic memory in MSC 6.0
From: Joe Huffman
Date: Tue, 26 Mar 1991 21:45
Date: Tue, 26 Mar 1991 21:45
44 lines
1893 bytes
1893 bytes
rkl@cbnewsh.att.com (kevin.laux) writes:
>In article <1991Mar25.095017.9802@cs.umu.se>, erikt@ume.cs.umu.se (Erik T{rnvik) writes:
>> I'm using Microsoft C 6.0 in a major project. During execution I need to know
>> how much (dynamic) memory is available for allocation. There are some functions
> Call Int 21h Function 48h (allocate memory) with BX set to FFFFh.
>This call will fail because you're asking for a megabyte of memory. *But*,
>it will return the size of the largest block available in BX. The value
>returned in BX is in paragraphs (16 bytes).
Sorry... nice try though. This only give you memory available from MSDOS
not from the heap. Try this little example (requires your int 21 function
to be built):
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *p;
printf("DOS says %ld bytes available\n",
(long)int_21_func_48_reg_BX() * 16);
p = malloc(60000); /* Assuming >= 60000 is available. */
free(p);
printf("Now DOS says %ld bytes available\n",
(long)int_21_func_48_reg_BX() * 16);
return 0;
}
What happens is that malloc() requests memory from DOS and free does
not return it to DOS. It is easy to create an example such that int 21h
func 48 will return 0 bytes available and actually have 100's of K
available from malloc().
I don't know of any other method than the 'obvious and stupid' test by
exhaustion. Suggestions welcome.
--
joe@proto.com
Technical Details
Message-ID:
<1991Mar26.214536.18451@proto.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!proto!joeReferences:
<1991Mar25.095017.9802@cs.umu.se> <1991Mar25.143624.24690@cbnewsh.att.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!proto!joe From: joe@proto.com (Joe Huffman) Newsgroups: comp.os.msdos.programmer Subject: Re: Available dynamic memory in MSC 6.0 Message-ID: <1991Mar26.214536.18451@proto.com> Date: 26 Mar 91 21:45:36 GMT References: <1991Mar25.095017.9802@cs.umu.se> <1991Mar25.143624.24690@cbnewsh.att.com> Organization: Prototronics @ Sandpoint, Idaho Lines: 44