Mail Archives: djgpp/1997/03/12/20:24:55
>this is the code i use : (long lines got wrapped with ...'s)
>it reports the memory as described above then says malloc failed. despite telling
>me it had at least 14meg and me only malloc'ing 6 meg of it!
Is the program failing in needmem() or in main(), after the call to
needmem()?
With DPMI you need to realize that the values returned from
__dpmi_get_free_memory_information (yes it is a long name), and the
corresponding _go32_dpmi_remaining_*() functions, are subject to change at
the whims of Windows/CWSDPMI/...
What MIGHT be happening is that the DPMI client reports only a small
amount of free memory, but if you malloc() a huge chunk it will get more
memory from the system for you, using virtual memory if appropriate. So
even if your program only got told it had 4 MB free you still might be
able to allocate a 64MB buffer.
When I first got DJGPP I wrote a program that allocated a 50 meg buffer
and filled it with zeros. It worked fine (on a 16 MB machine), but I
didn't have any checks for free memory first. Try this program and see if
it works:
--------[]--------
#include <stdio.h>
#include <string.h>
#define SIZE 50*1024*1024
main()
{
char* p = (char*) malloc(SIZE);
p ? memset(p, 0, SIZE), printf("worked\n") : printf("failed\n");
return 0;
}
--------[]--------
(apologies for obfuscation!)
Possible solution to problem: try the 14-meg malloc first, and if it
fails, then report free memory to user and abort.
--Dave
- Raw text -