From 113c4ba4d6780449afd4681e56b6aba07908402f Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Thu, 13 Nov 2008 03:40:02 +0000 Subject: -- Still working toward killing nbench1.h -- Removing AllocateMemory and FreeMemory calls git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@15 0d43b9a7-5ab2-4d7b-af9d-f64450cef757 --- stringsort.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'stringsort.c') diff --git a/stringsort.c b/stringsort.c index 7670dea..bf38981 100644 --- a/stringsort.c +++ b/stringsort.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -52,10 +53,10 @@ void DoStringSort(void) { SortStruct *strsortstruct; /* Local for sort structure */ -unsigned char *arraybase; /* Base pointer of char array */ +unsigned char *arraybase = NULL; /* Base pointer of char array */ long accumtime; /* Accumulated time */ double iterations; /* # of iterations */ -char *errorcontext; /* Error context string pointer */ +char *context; /* Error context string pointer */ int systemerror; /* For holding error code */ /* @@ -66,7 +67,7 @@ strsortstruct=&global_strsortstruct; /* ** Set the error context */ -errorcontext="CPU:String Sort"; +context="CPU:String Sort"; /* ** See if we have to perform self-adjustment code @@ -84,10 +85,10 @@ if(strsortstruct->adjust==0) ** bytes to protect memory as strings move around ** (this can happen during string adjustment) */ - arraybase=(unsigned char *)AllocateMemory((strsortstruct->arraysize+100L) * - (long)strsortstruct->numarrays,&systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); + arraybase = realloc(arraybase, (strsortstruct->arraysize + 100) * strsortstruct->numarrays); + if (!arraybase) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + exit(1); } /* @@ -101,7 +102,6 @@ if(strsortstruct->adjust==0) strsortstruct->arraysize)>global_min_ticks) break; /* We're ok...exit */ - FreeMemory((void *)arraybase,&systemerror); strsortstruct->numarrays+=1; } } @@ -111,11 +111,11 @@ else ** We don't have to perform self adjustment code. ** Simply allocate the space for the array. */ - arraybase=(unsigned char *)AllocateMemory((strsortstruct->arraysize+100L) * - (long)strsortstruct->numarrays,&systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - } + arraybase = malloc((strsortstruct->arraysize + 100) * strsortstruct->numarrays); + if (!arraybase) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + exit(1); + } } /* ** All's well if we get here. Repeatedly perform sorts until the @@ -322,12 +322,11 @@ while(k