diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-04-22 20:11:00 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-04-26 19:49:43 -0700 |
commit | f9e69902fbe143f72251721a305bd1f2466154e8 (patch) | |
tree | e8114555b0e6f6bbc7e738f444b8e02429ae4de3 /src/mixed_arena.h | |
parent | c8a7755461d5e806bd734b75f441ac61c9963ee9 (diff) | |
download | binaryen-f9e69902fbe143f72251721a305bd1f2466154e8.tar.gz binaryen-f9e69902fbe143f72251721a305bd1f2466154e8.tar.bz2 binaryen-f9e69902fbe143f72251721a305bd1f2466154e8.zip |
make chunk size flexible in arenas
Diffstat (limited to 'src/mixed_arena.h')
-rw-r--r-- | src/mixed_arena.h | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/mixed_arena.h b/src/mixed_arena.h index 3258a2d31..d8b487e4d 100644 --- a/src/mixed_arena.h +++ b/src/mixed_arena.h @@ -58,7 +58,8 @@ struct MixedArena { // fast bump allocation std::vector<char*> chunks; - int index; // in last chunk + size_t chunkSize = 32768; + size_t index; // in last chunk // multithreaded allocation - each arena is valid on a specific thread. // if we are on the wrong thread, we safely look in the linked @@ -88,11 +89,14 @@ struct MixedArena { } return curr->allocSpace(size); } - const size_t CHUNK = 10000; size = (size + 7) & (-8); // same alignment as malloc TODO optimize? - assert(size < CHUNK); - if (chunks.size() == 0 || index + size >= CHUNK) { - chunks.push_back(new char[CHUNK]); + bool mustAllocate = false; + while (chunkSize <= size) { + chunkSize *= 2; + mustAllocate = true; + } + if (chunks.size() == 0 || index + size >= chunkSize || mustAllocate) { + chunks.push_back(new char[chunkSize]); index = 0; } auto* ret = chunks.back() + index; |