Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2010 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef GrAllocPool_DEFINED |
michael@0 | 9 | #define GrAllocPool_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "SkTypes.h" |
michael@0 | 12 | |
michael@0 | 13 | class GrAllocPool : public SkNoncopyable { |
michael@0 | 14 | public: |
michael@0 | 15 | GrAllocPool(size_t blockSize = 0); |
michael@0 | 16 | ~GrAllocPool(); |
michael@0 | 17 | |
michael@0 | 18 | /** |
michael@0 | 19 | * Frees all blocks that have been allocated with alloc(). |
michael@0 | 20 | */ |
michael@0 | 21 | void reset(); |
michael@0 | 22 | |
michael@0 | 23 | /** |
michael@0 | 24 | * Returns a block of memory bytes size big. This address must not be |
michael@0 | 25 | * passed to realloc/free/delete or any other function that assumes the |
michael@0 | 26 | * address was allocated by malloc or new (because it hasn't). |
michael@0 | 27 | */ |
michael@0 | 28 | void* alloc(size_t bytes); |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * Releases the most recently allocated bytes back to allocpool. |
michael@0 | 32 | */ |
michael@0 | 33 | void release(size_t bytes); |
michael@0 | 34 | |
michael@0 | 35 | private: |
michael@0 | 36 | struct Block; |
michael@0 | 37 | |
michael@0 | 38 | Block* fBlock; |
michael@0 | 39 | size_t fMinBlockSize; |
michael@0 | 40 | |
michael@0 | 41 | #ifdef SK_DEBUG |
michael@0 | 42 | int fBlocksAllocated; |
michael@0 | 43 | void validate() const; |
michael@0 | 44 | #else |
michael@0 | 45 | void validate() const {} |
michael@0 | 46 | #endif |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | template <typename T> class GrTAllocPool { |
michael@0 | 50 | public: |
michael@0 | 51 | GrTAllocPool(int count) : fPool(count * sizeof(T)) {} |
michael@0 | 52 | |
michael@0 | 53 | void reset() { fPool.reset(); } |
michael@0 | 54 | T* alloc() { return (T*)fPool.alloc(sizeof(T)); } |
michael@0 | 55 | |
michael@0 | 56 | private: |
michael@0 | 57 | GrAllocPool fPool; |
michael@0 | 58 | }; |
michael@0 | 59 | |
michael@0 | 60 | #endif |