From: s335194 AT student DOT uq DOT edu DOT au (David Wilson) Newsgroups: comp.os.msdos.djgpp Subject: Re: problem with malloc in djgpp? Date: 12 Mar 1997 22:34:40 GMT Organization: University of Queensland Lines: 46 Message-ID: <5g7b20$uc$1@nargun.cc.uq.edu.au> References: <5g491r$mbg AT lyra DOT csx DOT cam DOT ac DOT uk> NNTP-Posting-Host: student.uq.edu.au To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp >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 #include #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