Skip to content

Commit

Permalink
Changed the memory allocation for HashTableBase::table from operator …
Browse files Browse the repository at this point in the history
…new/delete to malloc/free

This is done to facilitate initialize the table with memset().

Signed-off-by: saad0105050 <saad0105050@gmail.com>
  • Loading branch information
saad0105050 committed Sep 16, 2014
1 parent de8a991 commit 321f30c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions YASI_12/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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] ) )
Expand Down
9 changes: 7 additions & 2 deletions YASI_12/ds.hashtablebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 321f30c

Please sign in to comment.