aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/SkArenaAlloc.cpp3
-rw-r--r--src/core/SkArenaAlloc.h7
2 files changed, 9 insertions, 1 deletions
diff --git a/src/core/SkArenaAlloc.cpp b/src/core/SkArenaAlloc.cpp
index dee152ae20..779eaff0f1 100644
--- a/src/core/SkArenaAlloc.cpp
+++ b/src/core/SkArenaAlloc.cpp
@@ -100,7 +100,8 @@ void SkArenaAlloc::ensureSpace(uint32_t size, uint32_t alignment) {
objSizeAndOverhead += alignment - 1;
}
- uint32_t allocationSize = std::max(objSizeAndOverhead, fExtraSize);
+ uint32_t allocationSize = std::max(objSizeAndOverhead, fExtraSize << fLogGrowth);
+ fLogGrowth++;
// Round up to a nice size. If > 32K align to 4K boundary else up to max_align_t. The > 32K
// heuristic is from the JEMalloc behavior.
diff --git a/src/core/SkArenaAlloc.h b/src/core/SkArenaAlloc.h
index 3a6fd7d345..04f929181c 100644
--- a/src/core/SkArenaAlloc.h
+++ b/src/core/SkArenaAlloc.h
@@ -52,6 +52,10 @@
// typical block overhead of 8 bytes. For non-POD objects there is a per item overhead of 4 bytes.
// For arrays of non-POD objects there is a per array overhead of typically 8 bytes. There is an
// addition overhead when switching from POD data to non-POD data of typically 8 bytes.
+//
+// If additional blocks are needed they are increased exponentially. This strategy bounds the
+// recursion of the RunDtorsOnBlock to be limited to O(ln size-of-memory). In practical terms, this
+// is a maximum recursion depth of 33 for an 8GB machine but usually much less.
class SkArenaAlloc {
public:
SkArenaAlloc(char* block, size_t size, size_t extraSize = 0);
@@ -192,6 +196,9 @@ private:
char* const fFirstBlock;
const uint32_t fFirstSize;
const uint32_t fExtraSize;
+ // The extra size allocations grow exponentially:
+ // size-allocated = extraSize * 2 ^ fLogGrowth.
+ uint8_t fLogGrowth {0};
};
#endif//SkFixedAlloc_DEFINED