Public メソッド | |
sc_allocator (int blksz, int cellsz) | |
~sc_allocator () | |
void * | allocate () |
void | release (void *p) |
void | display_statistics () |
Private 変数 | |
int | block_size |
int | cell_size |
char * | block_list |
link * | free_list |
char * | next_avail |
int | total_alloc |
int | total_freed |
int | free_list_alloc |
フレンド | |
class | sc_mempool |
構成 | |
union | link |
sc_mempool.cpp の 83 行で定義されています。
sc_core::sc_allocator::sc_allocator | ( | int | blksz, | |
int | cellsz | |||
) |
sc_mempool.cpp の 113 行で定義されています。
00114 { 00115 cell_size = cellsz; 00116 block_size = sizeof(link) + (((blksz - 1) / cellsz) + 1) * cellsz; 00117 block_list = 0; 00118 free_list = 0; 00119 next_avail = 0; 00120 00121 total_alloc = 0; 00122 total_freed = 0; 00123 free_list_alloc = 0; 00124 }
sc_core::sc_allocator::~sc_allocator | ( | ) |
sc_mempool.cpp の 126 行で定義されています。
00127 { 00128 // Shouldn't free the block_list, since global objects that use 00129 // the memory pool may not have been destroyed yet ... 00130 // Let it leak, let it leak, let it leak ... 00131 }
void * sc_core::sc_allocator::allocate | ( | ) |
sc_mempool.cpp の 134 行で定義されています。
00135 { 00136 void* result = 0; 00137 total_alloc++; 00138 if (free_list != 0) { 00139 free_list_alloc++; 00140 result = free_list; 00141 free_list = free_list->next; 00142 return result; 00143 } 00144 else if (next_avail != 0) { 00145 result = next_avail; 00146 next_avail += cell_size; 00147 // next_avail goes beyond the block 00148 if (next_avail >= block_list + block_size) 00149 next_avail = 0; 00150 return result; 00151 } 00152 else { // (next_avail == 0) 00153 link* new_block = (link*) malloc(block_size); // need alignment? 00154 new_block->next = (link*) block_list; 00155 block_list = (char*) new_block; 00156 result = (block_list + sizeof(link)); 00157 // Assume that the block will hold more than one cell ... why 00158 // wouldn't it? 00159 next_avail = ((char*) result) + cell_size; 00160 return result; 00161 } 00162 }
void sc_core::sc_allocator::release | ( | void * | p | ) |
sc_mempool.cpp の 165 行で定義されています。
00166 { 00167 total_freed++; 00168 ((link*) p)->next = free_list; 00169 free_list = (link*) p; 00170 }
void sc_core::sc_allocator::display_statistics | ( | ) |
sc_mempool.cpp の 173 行で定義されています。
00174 { 00175 int nblocks = 0; 00176 for (link* b = (link*) block_list; b != 0; b = b->next) 00177 nblocks++; 00178 printf("size %3d: %2d block(s), %3d requests (%3d from free list), %3d freed.\n", 00179 cell_size, nblocks, total_alloc, free_list_alloc, total_freed); 00180 }
friend class sc_mempool [friend] |
sc_mempool.cpp の 84 行で定義されています。
int sc_core::sc_allocator::block_size [private] |
sc_mempool.cpp の 100 行で定義されています。
int sc_core::sc_allocator::cell_size [private] |
sc_mempool.cpp の 102 行で定義されています。
char* sc_core::sc_allocator::block_list [private] |
sc_mempool.cpp の 104 行で定義されています。
link* sc_core::sc_allocator::free_list [private] |
sc_mempool.cpp の 105 行で定義されています。
char* sc_core::sc_allocator::next_avail [private] |
sc_mempool.cpp の 106 行で定義されています。
int sc_core::sc_allocator::total_alloc [private] |
sc_mempool.cpp の 108 行で定義されています。
int sc_core::sc_allocator::total_freed [private] |
sc_mempool.cpp の 109 行で定義されています。
int sc_core::sc_allocator::free_list_alloc [private] |
sc_mempool.cpp の 110 行で定義されています。