usage() {
puts(
"Usage:\n"
- "memtest [-c COUNT [-m]]\n"
+ "memtest [-c COUNT [-t]]\n"
);
exit(1);
}
opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
opterr=0;
- while((i=getopt(argn,argv,"c:hm")) != EOF) {
+ while((i=getopt(argn,argv,"c:ht")) != EOF) {
switch(i) {
case 'c':
count=atoi(optarg);
break;
- case 'm':
+ case 't':
iscntx=1;
break;
case 'h':
*ptr = (i+3)%256;
}
+ freeMemoryContext(base);
printf("MC elapsed: %f sec\n", elapsedtime(&begin));
- freeMemoryContext(base);
} else {
+ char **all, **allptr;
gettimeofday(&begin, NULL);
+ allptr=all=malloc(sizeof(char*)*count*2);
+ if ( !all )
+ tlog(TL_CRIT|TL_EXIT,"No memory");
for(i=0;i<count;i++) {
ptr = malloc( 1+random()%SZ );
ptr1 = malloc( 1+random()%SZ );
tlog(TL_CRIT|TL_EXIT,"No memory");
*ptr = (i+1)%256;
- ptr1=malloc( 1+random()%SZ );
+ *allptr = ptr1=malloc( 1+random()%SZ );
+ allptr++;
*ptr1 = (i+2)%256;
- ptr = realloc(ptr, 1+random()%SZ );
+ *allptr = ptr = realloc(ptr, 1+random()%SZ );
+ allptr++;
if ( !ptr )
tlog(TL_CRIT|TL_EXIT,"No memory");
*ptr = (i+3)%256;
-
}
+ allptr=all;
+ while( allptr-all < count ) {
+ free(*allptr);
+ allptr++;
+ }
+ free(all);
printf("Malloc elapsed: %f sec\n", elapsedtime(&begin));
}