Mail Archives: djgpp/2000/09/26/10:37:18
On Tue, 26 Sep 2000, Rafael Garc=EDa wrote:
> > > Well, I have got sbrk(0) to return negative values in some cases, so =
the
> > > function tells I have -1950Kb.
> >
> > sbrk returns an insigned value, not a signed one. So negative values
> > are actually very large positive ones. Happens a lot on Windows.
>=20
> So... I cannot use that function I read somewhere to know available memor=
y?
You could use sbrk, but only up to a point: if the DPMI server returns=20
memory in a different area, your calculations will be wrong. You could=20
work around that by requesting Unixy sbrk algorithm, but that has=20
disadvantages in certain cases (see the docs of the _crt0_startup_flags=20
variable in the libc.info file, for more details).
> > Is there another method?
There are other methods, but they all suffer from a common problem: on=20
any OS except plain DOS, the DPMI server usually lies about available=20
memory, and there's no reliable way of counting the amount of memory used=
=20
by the client program. You need to be aware that in a virtual memory=20
environment, there's no easy way to know what memory is actually taken by=
=20
a process.
One possible way of tracking memory allocation would be by calling=20
_go32_dpmi_get_free_memory_information or=20
__dpmi_get_free_memory_information. Look them up in the library docs.
> Perhaps I must try malloc(1.5*filelength(f)) to decide if it is good idea=
to
> load entire file in ram
Why multiply by 1.5? Are you going to enlarge the data?
> but I thougth it would be better technique to watch
> available before. I think it is possible a long delay for virtual allocat=
ion
> if I ask for 20 Mb in a 2Mb ram machine
This is false: malloc only reserves the address space, but doesn't=20
actually page in the memory until you access it. (This is explained in=20
section 15.2 of the DJGPP FAQ list.) So using malloc is indeed the right=
=20
way of achieving what you want, even on memory-starved machines.
- Raw text -