ReserveArray.h

Go to the documentation of this file.
00001 
00007 /*
00008    ReserveArray template
00009    Uses simple contingous array allocation in a hidden manner
00010    so that array object can have items added without limit
00011    Suffers from memory fragmentation during resizing
00012    Fast access, safe and efficient passing of encapsulated array thru
00013    function arguments.
00014 */
00015 
00016 #if 0
00017 //  No longer in use and probably not the best solution anyway.
00018 
00019 #ifndef RESERVEARRAY_H
00020 #define RESERVEARRAY_H
00021 
00022 #define RESERVEARRAY(TYPE,NAME,RSIZE,SIZE) \
00023   TYPE * NAME; \
00024   ReserveArray<TYPE,RSIZE> NAME ## _reserve(SIZE,&NAME);
00025 
00026 template <class Elem, int reservedSize> class ReserveArray {
00027 
00028   Elem *allocatedStorage;
00029   Elem reservedStorage[reservedSize];
00030 
00031   public:
00032 
00033   ReserveArray(int size, Elem **userStorage) {
00034     if ( size > reservedSize ) {
00035       *userStorage = allocatedStorage = new Elem[size];
00036     } else if ( size > 0 ) {
00037       allocatedStorage = 0;
00038       *userStorage = reservedStorage;
00039     } else {
00040       allocatedStorage = 0;
00041       *userStorage = 0;
00042     }
00043   }
00044 
00045   ~ReserveArray() {
00046     delete [] allocatedStorage;
00047   }
00048 
00049 };
00050 
00051 #endif
00052 
00053 #endif
00054 

Generated on Sat Nov 18 01:17:15 2017 for NAMD by  doxygen 1.4.7