From 321f30caa36423f741350959be193035bc563269 Mon Sep 17 00:00:00 2001 From: saad0105050 Date: Mon, 15 Sep 2014 23:09:04 -0400 Subject: [PATCH] Changed the memory allocation for HashTableBase::table from operator new/delete to malloc/free This is done to facilitate initialize the table with memset(). Signed-off-by: saad0105050 --- YASI_12/common.h | 1 + YASI_12/ds.hashtablebase.h | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/YASI_12/common.h b/YASI_12/common.h index 7cbe827..1c31abc 100644 --- a/YASI_12/common.h +++ b/YASI_12/common.h @@ -24,6 +24,7 @@ namespace yasi{ #define MAKE_UNIQUE2(x,y) MAKE_UNIQUE( CONCAT(x,y) ) #define MAKE_UNIQUE3(x,y, z) MAKE_UNIQUE2( CONCAT(x,y), z ) +#define FREE_SAFE(x) {if( (x) != 0 ) free(x); (x) = 0; } #define DELETE_SAFE(x) {if( (x) != 0 ) delete (x); (x) = 0; } #define DELETE_ARR_SAFE(x) {if( (x) != 0 ) delete[] (x); (x) = 0; } #define ARR_LENGTH(x) ( sizeof( (x) )/sizeof( (x)[0] ) ) diff --git a/YASI_12/ds.hashtablebase.h b/YASI_12/ds.hashtablebase.h index 1a17038..673143b 100644 --- a/YASI_12/ds.hashtablebase.h +++ b/YASI_12/ds.hashtablebase.h @@ -142,10 +142,15 @@ class HashTableBase : public IKeyValueStore < Key, Value >{ HashTableBase():HashTableBase(INIT_LOGSIZE){} HashTableBase(unsigned int logSize = INIT_LOGSIZE) : _logSize(logSize), _size(1 << logSize), _population(0), DENSITY_MAX(0.75), DENSITY_MIN(0.25){ assert(_logSize > 0); - table = new BucketType[_size]; + // table = new BucketType[_size]; + table = (BucketType*)malloc(_size * sizeof(BucketType)); initTable(&table, _size); } - virtual ~HashTableBase(){ DELETE_ARR_SAFE(table); _size = _population = _logSize = 0; } + virtual ~HashTableBase(){ + // DELETE_ARR_SAFE(table); + FREE_SAFE(table); + _size = _population = _logSize = 0; + } inline unsigned int size(){ return _size; } inline unsigned int population(){ return _population; }