00001
00007
00008
00009
00010
00011 #ifndef OBJECTARENA_H
00012 #define OBJECTARENA_H
00013
00014 #include "ResizeArray.h"
00015
00016 template <class Type> class ObjectArena {
00017 public:
00018 ObjectArena(void) : blockSize(1024), alignment(1), pos(0), end(0) { };
00019 ~ObjectArena(void) {
00020 int i;
00021 for( i = 0; i < blocks.size(); ++i ) delete [] blocks[i];
00022 }
00023 void setBlockSize(int n) { blockSize = n; }
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 inline Type* getNewArray(int n) {
00050 Type *rpos = pos;
00051 if ( n > (blockSize/2) ) {
00052 rpos = new Type[n];
00053 blocks.add(rpos);
00054 } else if ( ( pos += n ) > end ) {
00055 rpos = pos = new Type[blockSize];
00056 blocks.add(pos);
00057 end = rpos + blockSize;
00058 pos += n;
00059 }
00060 return rpos;
00061 }
00062
00063 private:
00064 int blockSize;
00065 int alignment;
00066 ResizeArray<Type*> blocks;
00067 Type *pos, *end;
00068 };
00069
00070 #endif