From: Andrew Apted Date: Mon, 11 Sep 2000 15:54:41 +1000 To: djgpp AT delorie DOT com Subject: Malloc bug in DJGPP V2.03 Message-ID: <20000911155441.A493@ajax.netspace.net.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2i Reply-To: djgpp AT delorie DOT com I'm experiencing a problem with my DJGPP program (glBSP, a nodes builder for DOOM) where it runs out of memory under DOS, even though there should be plenty left. I've memory-profiled the code (under Linux), and the most it ever uses (not including overheads) is 9 MB, yet my machine has 64 MB RAM. This is with DJGPP V2.03. Below is a test program which can reproduce the problem, which is similiar to my program (it allocates lots of small objects, around 32 bytes each). The most it ever uses is 9 MB (excluding overheads in malloc), yet it always fails here with out of memory before reaching the end. The furthest it gets is POS 66, when CWSDPMI's internal heap parameter is [128], and POS 131 when it is [1024]. Also below is the output of go32-v2 etc... This is clearly a bug in DJGPP's malloc functions, right ? Cheers, __ \/ Andrew Apted ======================================================================== /* * TESTMEM */ #include #include typedef struct blob_s { struct blob_s *next; int data[7]; } blob_t; int main(void) { int i; int actual = 0; blob_t ** array[16] = { NULL, }; for (i=0; i < 256000; i++) { int hi = i % 16; // breadth first int lo = i / 16; if ((i % 1000) == 0) fprintf(stderr, "POS: %d/%d ACTUAL: %d\n", i / 1000, 255, actual); array[hi] = realloc(array[hi], (lo + 1) * sizeof(blob_t *)); actual += sizeof(blob_t *); if (array[hi] == NULL) { fprintf(stderr, "OUT OF MEMORY ! (realloc)\n"); return 1; } array[hi][lo] = calloc(1, sizeof(blob_t)); actual += sizeof(blob_t); if (array[hi][lo] == NULL) { fprintf(stderr, "OUT OF MEMORY ! (calloc)\n"); return 1; } (array[hi][lo])->data[0] = hi; (array[hi][lo])->data[1] = lo; } return 0; } ======================================================================== output of go32-v2: go32/v2 version 2.0 built Dec 24 1999 17:46:57 Usage: go32 coff-image [args] Rename this to go32.exe only if you need a go32 that can run v2 binaries as well as v1 binaries (old makefiles). Put ahead of the old go32 in your PATH but do not delete your old go32 - leave it in the PATH after this one. Set GO32_V2_DEBUG=y in the environment to get verbose output. DPMI memory available: 64455 Kb DPMI swap space available: 13617 Kb output of set: COMSPEC=C:\COMMAND.COM PATH=C:\DJGPP\BIN;C:\VIM-5.3;C:\LYNX\LYNX;C:\;C:\DOS;C:\WINDOWS;C:\AMOUSE;C:\UTILS;C:\TC;C:\XTGOLD;C:\ACRODOS TEMP=C:\TEMP SCSI_DRIVER=C:\IOMEGA SCSI_UTILITY=C:\IOMEGA DOOMWADDIR=C:\GAMES\DOOM2 BLASTER=A220 I7 D1 H5 P330 T6 DJGPP=C:\DJGPP\DJGPP.ENV PROMPT=$p$g DA=0 config.sys: DOS=HIGH DOS=UMB FILES=40 FCBS=40,0 BUFFERS=40 STACKS=9,256 LASTDRIVE=Z DEVICE=C:\WINDOWS\HIMEM.SYS DEVICEHIGH=C:\DOS\ANSI.SYS DEVICEHIGH=C:\WINDOWS\IFSHLP.SYS DEVICEHIGH=C:\SBCD\SBIDE.SYS /D:SBPCD /V /P:170,15,376 SHELL=C:COMMAND.COM /E:8192 /P autoexec.bat: @ECHO OFF PATH=C:\DJGPP\BIN;C:\VIM-5.3;C:\LYNX\LYNX;C:\;C:\DOS;C:\WINDOWS;C:\AMOUSE;C:\UTILS;C:\TC;C:\XTGOLD;C:\ACRODOS SET TEMP=C:\TEMP SET SCSI_DRIVER=C:\IOMEGA SET SCSI_UTILITY=C:\IOMEGA SET DOOMWADDIR=C:\GAMES\DOOM2 SET BLASTER=A220 I7 D1 H5 P330 T6 SET DJGPP=C:\DJGPP\DJGPP.ENV PROMPT $p$g C:\CDROMDRV\MSCDEX /D:SBPCD /L:R /M:8 /V C:\DOS\SMARTDRV /X 512 512 DOSKEY /INSERT MODE CON LINES=50 AMOUSE /R1 /C ECHO. MENU