00001 #ifndef __COMMON__SIMPLE_ALLOCATOR_H__
00002 #define __COMMON__SIMPLE_ALLOCATOR_H__
00003
00021 class OE_FIXED_ALLOCATOR
00022 {
00023 private:
00024 struct page_header_t {
00025 page_header_t *_next;
00026 unsigned int _count;
00027 };
00028
00029 void *_free;
00030 void *_first_page;
00031 const unsigned int _block_size;
00032
00033 public:
00035 OE_FIXED_ALLOCATOR(int block_size)
00036 :_free(NULL), first_page(NULL), _block_size(block_size)
00037 {
00038 }
00039
00041 ~OE_FIXED_ALLOCATOR()
00042 {
00043 while (_first_page) {
00044 page_header_t *next_page = _first_page->next;
00045 ::free(_first_page);
00046 _first_page = next_page;
00047 }
00048 }
00049
00051 void *alloc()
00052 {
00053 if (_free) {
00054 _free = (void*)(*_free);
00055 }
00056 }
00057
00058 };
00059
00060 #endif