//------------------------------Arena------------------------------------------ Arena::Arena( size_t init_size ) { init_size = (init_size+3) & ~3; _first = _chunk = new (init_size) Chunk(init_size); _hwm = _chunk->bottom(); // Save the cached hwm, max _max = _chunk->top(); set_size_in_bytes(init_size); }
Arena::Arena(size_t init_size) { size_t round_size = (sizeof (char *)) - 1; init_size = (init_size+round_size) & ~round_size; _first = _chunk = new (init_size) Chunk(init_size); _hwm = _chunk->bottom(); // Save the cached hwm, max _max = _chunk->top(); set_size_in_bytes(init_size); }
//------------------------------grow------------------------------------------- // Grow a new Chunk void* Arena::grow( size_t x ) { // Get minimal required size. Either real big, or even bigger for giant objs size_t len = max(x, Chunk::size); register Chunk *k = _chunk; // Get filled-up chunk address _chunk = new (len) Chunk(len); if( k ) k->_next = _chunk; // Append new chunk to end of linked list else _first = _chunk; _hwm = _chunk->bottom(); // Save the cached hwm, max _max = _chunk->top(); set_size_in_bytes(size_in_bytes() + len); void* result = _hwm; _hwm += x; return result; }
// Grow a new Chunk void* Arena::grow( size_t x ) { // Get minimal required size. Either real big, or even bigger for giant objs size_t len = MAX2(x, (size_t) Chunk::size); Chunk *k = _chunk; // Get filled-up chunk address _chunk = new (len) Chunk(len); if (_chunk == NULL) vm_exit_out_of_memory(len * Chunk::aligned_overhead_size(), "Arena::grow"); if (k) k->set_next(_chunk); // Append new chunk to end of linked list else _first = _chunk; _hwm = _chunk->bottom(); // Save the cached hwm, max _max = _chunk->top(); set_size_in_bytes(size_in_bytes() + len); void* result = _hwm; _hwm += x; return result; }
Arena::Arena(Arena *a) : _chunk(a->_chunk), _hwm(a->_hwm), _max(a->_max), _first(a->_first) { set_size_in_bytes(a->size_in_bytes()); }
Arena::Arena() { _first = _chunk = new (Chunk::init_size) Chunk(Chunk::init_size); _hwm = _chunk->bottom(); // Save the cached hwm, max _max = _chunk->top(); set_size_in_bytes(Chunk::init_size); }