00001 /* 00002 FALCON - The Falcon Programming Language. 00003 FILE: smba.h 00004 00005 Small Memory Block Allocator. 00006 ------------------------------------------------------------------- 00007 Author: Giancarlo Niccolai 00008 Begin: Sat, 13 Dec 2008 14:42:24 +0100 00009 00010 ------------------------------------------------------------------- 00011 (C) Copyright 2008: the FALCON developers (see list in AUTHORS file) 00012 00013 See LICENSE file for licensing details. 00014 */ 00015 00020 #ifndef FALCON_SMBA_H 00021 #define FALCON_SMBA_H 00022 00023 #include <falcon/setup.h> 00024 00025 namespace Falcon 00026 { 00027 00028 class Mutex; 00029 00048 class SmallMemBlockAlloc 00049 { 00050 protected: 00051 00052 typedef struct tag_Page 00053 { 00054 struct tag_Page *next; 00055 struct tag_Page *prev; 00056 void* firstFree; // for blank allocations 00057 short int allocated; 00058 short int pageArea; 00059 } PAGE_HEADER; 00060 00061 enum{ 00062 page_list_size = 4 00063 }; 00064 00066 PAGE_HEADER* page_lists[page_list_size]; 00067 00069 void* page_free_lists[page_list_size]; 00070 00071 // Using a pointer here because I don't want to include mt.h here. 00072 Mutex *m_mtx; 00073 00074 PAGE_HEADER* newPage( int blockSize ); 00075 00076 public: 00077 SmallMemBlockAlloc(); 00078 ~SmallMemBlockAlloc(); 00079 00087 void* alloc( unsigned int bytes ); 00088 00093 void free( void* bytes ); 00094 }; 00095 00096 extern SmallMemBlockAlloc SMBA; 00097 } 00098 00099 #endif 00100 00101 /* end of smba.h */