Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site allegra.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!allegra!jpl From: jpl@allegra.UUCP (John P. Linderman) Newsgroups: net.lang.c,net.bugs.4bsd Subject: Re: 4.2 malloc - one last time Message-ID: <5128@allegra.UUCP> Date: Wed, 18-Sep-85 12:37:09 EDT Article-I.D.: allegra.5128 Posted: Wed Sep 18 12:37:09 1985 Date-Received: Thu, 19-Sep-85 05:39:21 EDT References: <5123@allegra.UUCP> Organization: AT&T Bell Laboratories, Murray Hill Lines: 71 Xref: watmath net.lang.c:6455 net.bugs.4bsd:1756 I got mail from Matt Crawford (ihnp4!oddjob!matt) asking why it was that when he reallocated a huge area down to a small one with my test program, the huge area didn't seem to be available for subsequent allocations. Simple. My test program was buggy, and passed the wrong pointer to realloc. Here's the diff of a fix, and a new feature. If you compile both the test program and malloc with -DMSTATS, the `m' command will use the mstats call in malloc to describe space used and space free for the various bucket sizes. John P. Linderman allegra!jpl *** old talloc.c Tue Sep 17 08:45:35 1985 --- new talloc.c Wed Sep 18 10:50:19 1985 *************** *** 93,99 } else { (void) cvnum(p, &n); if (n > 0) last = n; ! if (p = realloc(p, last)) { (void) printf("%d: %d=>%d bytes from %#x to %#x\n", i, a[i].z, last, a[i].p, p); a[i].p = p; --- 93,99 ----- } else { (void) cvnum(p, &n); if (n > 0) last = n; ! if (p = realloc(a[i].p, last)) { (void) printf("%d: %d=>%d bytes from %#x to %#x\n", i, a[i].z, last, a[i].p, p); a[i].p = p; *************** *** 111,116 } } break; case 'q': exit(0); case '?': --- 111,121 ----- } } break; + #ifdef MSTATS + case 'm': + (void) mstats(p+1); + break; + #endif case 'q': exit(0); case '?': *************** *** 116,121 case '?': (void) printf("a [N] => allocate N bytes, report index\n"); (void) printf("f index => free space at index\n"); (void) printf("r index [N] => reallocate N bytes at index\n"); (void) printf("s => print summary of allocated storage\n"); (void) printf("q => quit\n"); --- 121,129 ----- case '?': (void) printf("a [N] => allocate N bytes, report index\n"); (void) printf("f index => free space at index\n"); + #ifdef MSTATS + (void) printf("m [title] => print malloc statistics\n"); + #endif (void) printf("r index [N] => reallocate N bytes at index\n"); (void) printf("s => print summary of allocated storage\n"); (void) printf("q => quit\n");