#ifndef DATASTORE_H #define DATASTORE_H #include #include /** The RegionDetectorMemoryManager offers the ability of dynamic memory handling without allocation of new data at runtime (unless the fill-factor has reached 100%. In this case the underlying memory array is reallocated with double size. */ namespace icl{ namespace regiondetector{ template class RegionDetectorMemoryManager{ public: typedef T** iterator; inline RegionDetectorMemoryManager(int size=0, int growfactor=0){ if(size == 0)size = INITIAL_CAPACITY; if(growfactor == 0) growfactor = DEF_GROW_FACTOR; //data = new T*[size]; data = (T**)malloc(size*sizeof(T*)); for(int i=0;igrowfactor = growfactor; curr_index = 0; } inline ~RegionDetectorMemoryManager(){ //delete [] data; for(int i=0;imem(); } return n; } void shrink(){ if(curr_size < INITIAL_CAPACITY) return; //printf("calling \"shrink\" oldsize = %d newsize = %d\n",curr_size,(int)(curr_size/growfactor)); int old_size = curr_size; curr_size/=growfactor; T** new_data = (T**)malloc(sizeof(T)*curr_size); memcpy(new_data,data,curr_size*sizeof(T*)); for(int i=curr_size;i