malloc(3) vs. malloc(3x)
Robert Seals
rds95 at leah.Albany.Edu
Sat Jan 7 02:32:36 AEST 1989
How much can a single malloc get? And why does Ultrix have 2 kinds of
malloc, while 4.3-tahoe (the first one, I think) only has 1?
Here's a little thing I wrote to see how big a chunk I could get from a
single malloc...
Script started on Fri Jan 6 10:06:45 1989
14 more days of President Reagan
% cat tst.c
#include <stdio.h>
#include <malloc.h> /* not in 4.3-tahoe */
void main()
{
char *x;
unsigned int i, j;
for (i=10000; (x=malloc(i)) != NULL; i+=10000)
free(x);
i -= 10000;
printf("%d\n", i);
for (j=i; (x=malloc(j)) != NULL; j+=10)
free(x);
printf("%d\n", j - 10);
}
% gcc -O -s -Wall -o tst tst.c
tst.c: In function main:
tst.c:14: warning: implicit declaration of function `printf'
% time tst
4190000
4194300
0.1u 0.3s 0:00 83% 3+19k 0+0io 5pf+0w
% gcc -O -s -Wall -o tst tst.c -lmalloc
tst.c: In function main:
tst.c:14: warning: implicit declaration of function `printf'
% time tst
6620000
6619990
0.2u 1.3s 0:01 89% 8+780k 0+0io 9pf+0w
% ^D
script done on Fri Jan 6 10:08:34 1989
Eh? I thought that there must be some resource limit defined by the system,
and in Ultrix (1.2 and 2.2), there is a "ulimit" call, but 4.3-tahoe
only has "getrlimit", so I wrote a little smidge to find out what my
"RLIMIT_DATA" and "RLIMIT_RSS" were. They were way bigger than the
amount I got from malloc. Are they the right thing to check?
So I thought mebbe a physical memory limit? Nah, why would I (consistently)
get 2 different values depending on the library version I used?
Like, what good is virtual memory if I can't malloc New Jersey? );
AND, why did the 3x version (the one used when -lmalloc is included)
have such extravagant core(?) requirements - 780k vs. 19k for libc?
AND, why isn't there a (old-style) prototype for malloc anywhere in
/usr/include, even though it doesn't return an int? Isn't that the
way it's supposed to go? Like /usr/include/malloc.h...char *malloc();...
Remember, this is the NEOPHYTES group, so keep the fires low.
rob
More information about the Comp.unix.questions
mailing list