Mail Archives: djgpp/1997/03/11/16:03:37
i remember seeing something just recently about memory fragmentation problems
with djgpp malloc and wondered if it was decided whose fault this was :)
i have a program which has weird malloc problems and wondered if fragmentation
could be the problem.
on startup the program claims (under pure dos) that it has 0.7meg real and 121meg
virtual memory available. it now allocates some blocks of memory but in doing so
causes a page fault. probably due to the incredibly low amount of real memory i
thought, so i tried to run this under win3.1
now i get 7.1meg real and 120meg virtual available. this should be enough to
allocate the 14meg buffer that i require though.
dpmi_free_memory, or whatever the hugely long name for it is, says it has
127.1meg total therefore. but malloc returns a null pointer when i try to dim the
block. why on earth should this be the case? the program works fine on a 32meg
machine incidentally. the problem only occurs on 8 and 16 meg machines. the
program is not locked in memory, it uses cwsdpmi.exe so should have access to the
virtual memory right?
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!
thanks.
nik
---
void main()
{
printf("%.1fMB (+%.1fMB) of memory available.\n",
((float)_go32_dpmi_remaining_physical_memory())/0x100000,
((float)_go32_dpmi_remaining_virtual_memory())/0x100000);
// we need 14 meg just to decode these files
needmem(6L*1024*1024+1024L*1024*8);
if ((ydata=(unsigned char *)malloc(6L*1024*1024))==NULL) {
// ydata is defined in a header file as unsigned char *ydata
// a really bad error which should never have happened.
closedown();
printf("Insufficient memory to run. malloc failed.\n");
printf("a truly bad thing happened and should have been...
caught by needmem.\n");
exit(0);
}
}
unsigned int needmem(unsigned int amount)
{
if (_go32_dpmi_remaining_physical_memory()+_go32_dpmi_remaining_...
virtual_memory()<amount) {
// not enough memory for upcoming mallocs
closedown(); // shut down system
printf("Insufficient memory to run\n");
printf("(Request for %.1fMB but only %.1fMB of memory...
available)\n",(float)amount/0x100000,((float)_go32_dpmi_...
remaining_physical_memory()+_go32_dpmi_remaining_virtual_...
memory())/0x100000);
exit(0);
}
return(_go32_dpmi_remaining_physical_memory());
// the above line is deliberate.
}
--
- Raw text -