X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f Message-ID: <3CB75923.C43539D5@yahoo.com> From: CBFalconer Organization: Ched Research X-Mailer: Mozilla 4.75 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: New DJGPP hogs memory (was: I need help) References: <5 DOT 0 DOT 2 DOT 1 DOT 0 DOT 20020410122845 DOT 00bcbbd8 AT pop DOT mail DOT yahoo DOT com> <5 DOT 0 DOT 2 DOT 1 DOT 0 DOT 20020410122845 DOT 00bcbbd8 AT pop DOT mail DOT yahoo DOT com> <5 DOT 0 DOT 2 DOT 1 DOT 0 DOT 20020411161942 DOT 00bd1eb0 AT pop DOT mail DOT yahoo DOT com> <2593-Fri12Apr2002115014+0300-eliz AT is DOT elta DOT co DOT il> <3CB6C8FA DOT 45A31BB7 AT yahoo DOT com> <3CB71962 DOT 1D21ED00 AT yahoo DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 141 Date: Fri, 12 Apr 2002 22:17:04 GMT NNTP-Posting-Host: 12.90.169.131 X-Complaints-To: abuse AT worldnet DOT att DOT net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1018649824 12.90.169.131 (Fri, 12 Apr 2002 22:17:04 GMT) NNTP-Posting-Date: Fri, 12 Apr 2002 22:17:04 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Eli Zaretskii wrote: > ... snip ... > > That's because you forgot a -c in "gcc -o evilalgo.o evilalgo.c", so > evilalgo.o is actually an executable program, with all the library > functions already linked in, not just an object file. Now that Eli has saved me from myself, I could run the various tests. First, the code used (I cleaned it up a bit): -------------- evilalgo.c ------------- /* From djgpp mail list - an evil algorithm */ #include #include typedef struct { char af[10]; char name[10]; } record; record **dt, *d; int main(int argc, char ** argv) { unsigned long n = 1000; /* was 200000L */ unsigned int count; if (argc > 1) n = strtoul(argv[1], NULL, 10); dt = NULL; for (count = 0; count < n; count++){ dt = realloc(dt, (count + 1) * sizeof *dt); d = dt[count] = calloc(10, sizeof *d); if (!(count & 0xfff)) putc('*', stderr); } return(0); } /* evilalgo */ -------------- end evilalgo.c ------------- And the results on my machine (64 M ram, 486/80). evilalgo.exe uses the original malloc, while a.exe uses my revised nmalloc. Posted as quote to avoid wrapping: > [1] c:\c\malloc>gcc -o evilalgo.o -c evilalgo.c > > [1] c:\c\malloc>gcc -o evilalgo.exe evilalgo.o > > [1] c:\c\malloc>gcc evilalgo.o malloc.o > > [1] c:\c\malloc>timerun evilalgo 10000 > Timer 3 on: 17:05:59 > ***Timer 3 off: 17:06:00 Elapsed: 0:00:01.49 > > [1] c:\c\malloc>timerun a 10000 > Timer 3 on: 17:06:21 > ***Timer 3 off: 17:06:22 Elapsed: 0:00:00.77 > > [1] c:\c\malloc>timerun evilalgo 10000 > Timer 3 on: 17:06:47 > ***Timer 3 off: 17:06:48 Elapsed: 0:00:01.26 > > [1] c:\c\malloc>timerun evilalgo 100000 > Timer 3 on: 17:08:24 > ***********Exiting due to signal SIGSEGV > Page fault at eip=00001659, error=0006 > eax=040e9d00 ebx=00008360 ecx=00000000 edx=00029830 esi=00000054 edi=0000d150 > ebp=004a0fe0 esp=004a0fc8 program=C:\C\MALLOC\EVILALGO.EXE > cs: sel=00a7 base=8360a000 limit=04140fff > ds: sel=00af base=8360a000 limit=04140fff > es: sel=00af base=8360a000 limit=04140fff > fs: sel=0087 base=0000b600 limit=0000ffff > gs: sel=00bf base=00000000 limit=0010ffff > ss: sel=00af base=8360a000 limit=04140fff > App stack: [004a1000..00421000] Exceptn stack: [0000d0b0..0000b170] > > Call frame traceback EIPs: > 0x00001659 main+153, file c:/c/malloc/evilalgo.c, line 22 > 0x00002a72 __crt1_startup+178 > Timer 3 off: 17:09:06 Elapsed: 0:00:42.23 > > [1] c:\c\malloc>bfdsymify evilalgo.exe > > [1] c:\c\malloc>timerun a 100000 > Timer 3 on: 17:18:04 > *************************Timer 3 off: 17:18:09 Elapsed: 0:00:05.21 > > [1] c:\c\malloc>timerun evilalgo 30000 > Timer 3 on: 17:21:18 > ********Timer 3 off: 17:21:24 Elapsed: 0:00:05.76 > > [1] c:\c\malloc>timerun a 30000 > Timer 3 on: 17:21:36 > ********Timer 3 off: 17:21:38 Elapsed: 0:00:01.82 > > [1] c:\c\malloc>timerun evilalgo 45000 > Timer 3 on: 17:22:42 > ***********Exiting due to signal SIGSEGV > Page fault at eip=00001659, error=0006 > eax=040e9d00 ebx=00008360 ecx=00000000 edx=00029830 esi > ebp=004a0fe0 esp=004a0fc8 program=C:\C\MALLOC\EVILALGO. > cs: sel=00a7 base=8360a000 limit=04140fff > ds: sel=00af base=8360a000 limit=04140fff > es: sel=00af base=8360a000 limit=04140fff > fs: sel=0087 base=0000b600 limit=0000ffff > gs: sel=00bf base=00000000 limit=0010ffff > ss: sel=00af base=8360a000 limit=04140fff > App stack: [004a1000..00421000] Exceptn stack: [0000d0 > > Call frame traceback EIPs: > 0x00001659 > 0x00002a72 > Timer 3 off: 17:23:11 Elapsed: 0:00:28.84 > > [1] c:\c\malloc>timerun evilalgo 40000 > Timer 3 on: 17:23:52 > **********Timer 3 off: 17:24:00 Elapsed: 0:00:08.63 > > [1] c:\c\malloc>timerun a 40000 > Timer 3 on: 17:24:20 > **********Timer 3 off: 17:24:22 Elapsed: 0:00:02.25 -------------------- and now my conclusions: First, nmalloc seems to have had no faults shown up with this. It appears to handle this continuous realloc about 2 to 4 times faster, and to use less memory in the aggregate. Note that evilalgo segfaulted with an input parameter of 45000, while nmalloc lets it handle at least 100000 without squealing (with my memory constraints). Lets get nmalloc further checked and into the library, which is why I wrote it in the first place. Don't forget it also reduces the O(N) free to O(1) and has hooks for arena tracing. -- Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT worldnet DOT att DOT net) Available for consulting/temporary embedded and systems. USE worldnet address!