jpl@allegra.UUCP (John P. Linderman) (09/17/85)
I am posting a test program and some extended commentary about my 4.2 malloc fixes to net.sources. John P. Linderman allegra!jpl
jpl@allegra.UUCP (John P. Linderman) (09/18/85)
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");