#ifndef OPP_SLAB_H #define OPP_SLAB_H template class slabptr { public: char index; slabptr(void) : index(N) {} slabptr(char i) : index(i) {} slabptr(const slabptr & i) : index(i.index) {} auto operator-> (); auto & operator* (); }; template class slab { protected: static __striped T buffer[N]; static char head; static char next[N]; public: typedef slabptr ptr; static void init(void); static auto alloc(void); static void free(ptr p); }; template inline auto slabptr::operator-> () { return slab::buffer + index; } template inline auto & slabptr::operator* () { return slab::buffer[index]; } template void slab::init(void) { head = 0; for(char i=0; i auto slab::alloc(void) { char i = head; head = next[head]; return slabptr(i); } template void slab::free(slabptr p) { next[p.index] = head; head = p.index; } #endif