SkVarAlloc.h revision bc415389855888af5a1282ca4b6bee30afa3d69d
1#ifndef SkVarAlloc_DEFINED
2#define SkVarAlloc_DEFINED
3
4#include "SkTypes.h"
5
6class SkVarAlloc : SkNoncopyable {
7public:
8    SkVarAlloc();
9    ~SkVarAlloc();
10
11    // Returns contiguous bytes aligned at least for pointers.  You may pass SK_MALLOC_THROW, etc.
12    char* alloc(size_t bytes, unsigned sk_malloc_flags) {
13        bytes = SkAlignPtr(bytes);
14
15        if (bytes > fRemaining) {
16            this->makeSpace(bytes, sk_malloc_flags);
17        }
18        SkASSERT(bytes <= fRemaining);
19
20        char* ptr = fByte;
21        fByte += bytes;
22        fRemaining -= bytes;
23        return ptr;
24    }
25
26private:
27    void makeSpace(size_t bytes, unsigned flags);
28
29    char* fByte;
30    unsigned fRemaining;
31    unsigned fLgMinSize;
32
33    struct Block;
34    Block* fBlock;
35};
36
37#endif//SkVarAlloc_DEFINED
38