OLD | NEW |
(Empty) | |
| 1 #ifndef SkVarAlloc_DEFINED |
| 2 #define SkVarAlloc_DEFINED |
| 3 |
| 4 #include "SkTypes.h" |
| 5 |
| 6 class SkVarAlloc : SkNoncopyable { |
| 7 public: |
| 8 // SkVarAlloc will never allocate less than smallest bytes at a time. |
| 9 // When it allocates a new block, it will be at least growth times bigger th
an the last. |
| 10 SkVarAlloc(size_t smallest, float growth); |
| 11 ~SkVarAlloc(); |
| 12 |
| 13 // Returns contiguous bytes aligned at least for pointers. You may pass SK_
MALLOC_THROW, etc. |
| 14 char* alloc(size_t bytes, unsigned sk_malloc_flags) { |
| 15 bytes = SkAlignPtr(bytes); |
| 16 |
| 17 if (fByte + bytes > fLimit) { |
| 18 this->makeSpace(bytes, sk_malloc_flags); |
| 19 } |
| 20 SkASSERT(fByte + bytes <= fLimit); |
| 21 |
| 22 char* ptr = fByte; |
| 23 fByte += bytes; |
| 24 return ptr; |
| 25 } |
| 26 |
| 27 private: |
| 28 void makeSpace(size_t bytes, unsigned flags); |
| 29 |
| 30 char* fByte; |
| 31 const char* fLimit; |
| 32 |
| 33 unsigned fSmallest; |
| 34 const float fGrowth; |
| 35 |
| 36 struct Block; |
| 37 Block* fBlock; |
| 38 }; |
| 39 |
| 40 #endif//SkVarAlloc_DEFINED |
OLD | NEW |