aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkVarAlloc.h
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-11-12 15:15:28 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-12 15:15:28 -0800
commit8113dd13692bc2e1fe804141d04b2cc5f03a55be (patch)
tree9b97a842f55452869a1576a3fb07cd300f114698 /src/core/SkVarAlloc.h
parentb122ee50fb56cf6669fe1668b82c8815896e9943 (diff)
SkVarAlloc
Like SkChunkAlloc, but - does its allocation with better sympathy for malloc granularity; - the fast path inlines entirely; - smaller per-block overhead; - smaller per-SkVarAlloc overhead; - growth parameters are a little more tunable. Its main downside is less flexibility; it supports fewer methods than SkChunkAlloc. These current parameters bring the first allocation down from 4K to 1K, without affecting recording time on my desktop. skiaperf.com will tell the whole story. BUG=skia: Review URL: https://codereview.chromium.org/674263002
Diffstat (limited to 'src/core/SkVarAlloc.h')
-rw-r--r--src/core/SkVarAlloc.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/core/SkVarAlloc.h b/src/core/SkVarAlloc.h
new file mode 100644
index 0000000000..0a7864b37a
--- /dev/null
+++ b/src/core/SkVarAlloc.h
@@ -0,0 +1,40 @@
+#ifndef SkVarAlloc_DEFINED
+#define SkVarAlloc_DEFINED
+
+#include "SkTypes.h"
+
+class SkVarAlloc : SkNoncopyable {
+public:
+ // SkVarAlloc will never allocate less than smallest bytes at a time.
+ // When it allocates a new block, it will be at least growth times bigger than the last.
+ SkVarAlloc(size_t smallest, float growth);
+ ~SkVarAlloc();
+
+ // Returns contiguous bytes aligned at least for pointers. You may pass SK_MALLOC_THROW, etc.
+ char* alloc(size_t bytes, unsigned sk_malloc_flags) {
+ bytes = SkAlignPtr(bytes);
+
+ if (fByte + bytes > fLimit) {
+ this->makeSpace(bytes, sk_malloc_flags);
+ }
+ SkASSERT(fByte + bytes <= fLimit);
+
+ char* ptr = fByte;
+ fByte += bytes;
+ return ptr;
+ }
+
+private:
+ void makeSpace(size_t bytes, unsigned flags);
+
+ char* fByte;
+ const char* fLimit;
+
+ unsigned fSmallest;
+ const float fGrowth;
+
+ struct Block;
+ Block* fBlock;
+};
+
+#endif//SkVarAlloc_DEFINED