00001
00006 #ifndef ONCE_ALLOC_H
00007 #define ONCE_ALLOC_H
00008 #include"rpointer.h"
00009 #include"growingmseg.h"
00010
00011 namespace RAMS
00012 {
00019 class Oncealloc
00020 {
00021 protected:
00022 Growingmseg mseg;
00023 RcharPointer akt;
00024 RcharPointer ao;
00025 long align;
00026 public:
00031 Oncealloc(int ini=1,long a=4):akt(0,&mseg),ao(0,&mseg)
00032 { mseg.grow(ini); align=a;
00033 }
00034
00038 RcharPointer neu()
00039 { ao.setoff(align2(align,ao.offset()));
00040 akt=ao;
00041 return akt;
00042 }
00043
00047 RcharPointer aktuell() { return akt; }
00051 RcharPointer aktende() { return ao; }
00052
00060 void grow1(char c) throw(Growingmseg::Error)
00061 {
00062 if(ao.offset()>=mseg.length()) mseg.grow(1);
00063 *(ao.ptr())=c;
00064 ao+=1;
00065 }
00066
00072 void garant(int l) throw(Growingmseg::Error)
00073 {
00074 if(ao.offset()+l > mseg.length())
00075 {
00076 long al=align2(getpagesize(),l)/getpagesize();
00077 mseg.grow(al);
00078 }
00079 }
00080
00086 RcharPointer reserve(int l) throw(Growingmseg::Error)
00087 {
00088 garant(l);
00089 ao+=l;
00090 return akt;
00091 }
00092
00098 RcharPointer alloc(int l) throw(Growingmseg::Error)
00099 {
00100 neu();
00101 return reserve(l);
00102 }
00103
00107 Mseg *getmseg() { return &mseg; }
00108
00112 long reallength() const { return ao.offset(); }
00113
00119 void write2file(char *filename) throw(Systemerror);
00120 };
00121 }
00122 #endif