19 #ifndef PAGESPEED_KERNEL_BASE_ARENA_H_
20 #define PAGESPEED_KERNEL_BASE_ARENA_H_
25 #include "base/logging.h"
28 namespace net_instaweb {
45 CHECK(chunks_.empty());
52 DCHECK(
sizeof(
void*) <=
kAlign);
53 DCHECK(size < Chunk::kSize);
55 if (next_alloc_ + size > chunk_end_) {
59 char* base = next_alloc_;
64 char** our_last_link_field =
reinterpret_cast<char**
>(base);
66 *our_last_link_field = NULL;
67 last_link_ = our_last_link_field;
74 DCHECK((reinterpret_cast<uintptr_t>(out) & (kAlign - 1)) == 0);
105 static const size_t kSize = 8192;
130 std::vector<Chunk*> chunks_;
134 void Arena<T>::AddChunk() {
135 Chunk* chunk =
new Chunk();
136 chunks_.push_back(chunk);
137 next_alloc_ = chunk->buf;
138 chunk_end_ = next_alloc_ + Chunk::kSize;
139 last_link_ = &scratch_;
144 for (
int i = 0; i < static_cast<int>(chunks_.size()); ++i) {
146 char* base = chunks_[i]->buf;
147 while (base != NULL) {
148 reinterpret_cast<T*
>(base + kAlign)->~T();
149 base = *
reinterpret_cast<char**
>(base);
static size_t ExpandToAlign(size_t in)
Rounds block size up to 8; we always align to it, even on 32-bit.
Definition: arena.h:82
void * Allocate(size_t size)
Definition: arena.h:48
void DestroyObjects()
Cleans up all the objects in the arena. You must call this explicitly.
Definition: arena.h:143
static const size_t kAlign
Definition: arena.h:38