more coorect comparing
authorteodor <teodor>
Thu, 10 Feb 2005 16:46:25 +0000 (16:46 +0000)
committerteodor <teodor>
Thu, 10 Feb 2005 16:46:25 +0000 (16:46 +0000)
memtest.c

index 2cb2040..223b49b 100644 (file)
--- a/memtest.c
+++ b/memtest.c
@@ -41,7 +41,7 @@ static void
 usage() {
        puts(
        "Usage:\n"
-       "memtest [-c COUNT [-m]]\n"
+       "memtest [-c COUNT [-t]]\n"
        );
        exit(1);
 }
@@ -60,12 +60,12 @@ main(int argn, char *argv[]) {
        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':
@@ -156,11 +156,15 @@ main(int argn, char *argv[]) {
                                *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 );
@@ -175,15 +179,22 @@ main(int argn, char *argv[]) {
                                        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));
                }