summaryrefslogtreecommitdiff
path: root/stringsort.c
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-13 03:40:02 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-13 03:40:02 +0000
commit113c4ba4d6780449afd4681e56b6aba07908402f (patch)
treecd9336ae17b88153a4a1fc452ef6be1320f66ee7 /stringsort.c
parent37438ca202a9a1f4e782f1d1803686fc6b65e918 (diff)
-- 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
Diffstat (limited to 'stringsort.c')
-rw-r--r--stringsort.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/stringsort.c b/stringsort.c
index 7670dea..bf38981 100644
--- a/stringsort.c
+++ b/stringsort.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <string.h>
#include <math.h>
#include <limits.h>
@@ -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<numarrays)
** Now the array is full, allocate enough space for an
** offset pointer array.
*/
-optrarray=(unsigned long *)AllocateMemory(*nstrings * sizeof(unsigned long) *
- numarrays,
- &systemerror);
-if(systemerror)
-{ ReportError("CPU:Stringsort",systemerror);
- FreeMemory((void *)strarray,&systemerror);
+optrarray = malloc(*nstrings * sizeof(unsigned long) * numarrays);
+if (!optrarray) {
+ /* FIXME: add error message */
+ free(strarray);
+ exit(1);
}
/*