summaryrefslogtreecommitdiff
path: root/huffman.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 /huffman.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 'huffman.c')
-rw-r--r--huffman.c69
1 files changed, 39 insertions, 30 deletions
diff --git a/huffman.c b/huffman.c
index 063b2ad..9d6aa7e 100644
--- a/huffman.c
+++ b/huffman.c
@@ -1,9 +1,13 @@
-#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <stdint.h>
+#include <string.h>
+#include <math.h>
+#include <limits.h>
+
#include "nmglobal.h"
#include "nbench1.h"
-
/************************
** HUFFMAN COMPRESSION **
************************/
@@ -112,13 +116,13 @@ char *wordcatarray[WORDCATSIZE] = { /* FIXME: const? */
void DoHuffman(void)
{
HuffStruct *lochuffstruct; /* Loc pointer to global data */
-char *errorcontext;
+char *context;
int systemerror;
unsigned long accumtime;
double iterations;
-char *comparray;
-char *decomparray;
-char *plaintext;
+char *comparray = NULL;
+char *decomparray = NULL;
+char *plaintext = NULL;
/*
** Link to global data
@@ -128,7 +132,7 @@ lochuffstruct=&global_huffstruct;
/*
** Set error context.
*/
-errorcontext="CPU:Huffman";
+context="CPU:Huffman";
/*
** Allocate memory for the plaintext and the compressed text.
@@ -141,29 +145,34 @@ errorcontext="CPU:Huffman";
** than 512 bytes. This is actually a super-conservative
** estimate...but, who cares?)
*/
-plaintext=(char *)AllocateMemory(lochuffstruct->arraysize,&systemerror);
-if(systemerror)
-{ ReportError(errorcontext,systemerror);
+plaintext = malloc(lochuffstruct->arraysize);
+if (!plaintext) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ exit(1);
}
-comparray=(char *)AllocateMemory(lochuffstruct->arraysize,&systemerror);
-if(systemerror)
-{ ReportError(errorcontext,systemerror);
- FreeMemory(plaintext,&systemerror);
+
+comparray = malloc(lochuffstruct->arraysize);
+if (!comparray) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ free(plaintext);
+ exit(1); /* FIXME: do I need exits here? */
}
-decomparray=(char *)AllocateMemory(lochuffstruct->arraysize,&systemerror);
-if(systemerror)
-{ ReportError(errorcontext,systemerror);
- FreeMemory(plaintext,&systemerror);
- FreeMemory(comparray,&systemerror);
+
+decomparray = malloc(lochuffstruct->arraysize);
+if (!decomparray) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ free(plaintext);
+ free(comparray);
+ exit(1);
}
-hufftree=(huff_node *)AllocateMemory(sizeof(huff_node) * 512,
- &systemerror);
-if(systemerror)
-{ ReportError(errorcontext,systemerror);
- FreeMemory(plaintext,&systemerror);
- FreeMemory(comparray,&systemerror);
- FreeMemory(decomparray,&systemerror);
+hufftree = malloc(sizeof(huff_node) * 512);
+if (!hufftree) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ free(plaintext);
+ free(comparray);
+ free(decomparray);
+ exit(1);
}
/*
@@ -221,10 +230,10 @@ do {
** Clean up, calculate results, and go home. Be sure to
** show that we don't have to rerun adjustment code.
*/
-FreeMemory((void *)plaintext,&systemerror);
-FreeMemory((void *)comparray,&systemerror);
-FreeMemory((void *)decomparray,&systemerror);
-FreeMemory((void *)hufftree,&systemerror);
+free(plaintext);
+free(comparray);
+free(decomparray);
+free(hufftree);
lochuffstruct->iterspersec=iterations / TicksToFracSecs(accumtime);
if(lochuffstruct->adjust==0)