OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrMemoryPool_DEFINED | 8 #ifndef GrMemoryPool_DEFINED |
9 #define GrMemoryPool_DEFINED | 9 #define GrMemoryPool_DEFINED |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 /** | 36 /** |
37 * p must have been returned by allocate() | 37 * p must have been returned by allocate() |
38 */ | 38 */ |
39 void release(void* p); | 39 void release(void* p); |
40 | 40 |
41 /** | 41 /** |
42 * Returns true if there are no unreleased allocations. | 42 * Returns true if there are no unreleased allocations. |
43 */ | 43 */ |
44 bool isEmpty() const { return fTail == fHead && !fHead->fLiveCount; } | 44 bool isEmpty() const { return fTail == fHead && !fHead->fLiveCount; } |
45 | 45 |
| 46 /** |
| 47 * Returns the total allocated size of the GrMemoryPool |
| 48 */ |
| 49 size_t size() const { return fSize; } |
| 50 |
46 private: | 51 private: |
47 struct BlockHeader; | 52 struct BlockHeader; |
48 | 53 |
49 static BlockHeader* CreateBlock(size_t size); | 54 static BlockHeader* CreateBlock(size_t size); |
50 | 55 |
51 static void DeleteBlock(BlockHeader* block); | 56 static void DeleteBlock(BlockHeader* block); |
52 | 57 |
53 void validate(); | 58 void validate(); |
54 | 59 |
55 struct BlockHeader { | 60 struct BlockHeader { |
56 BlockHeader* fNext; ///< doubly-linked list of blocks. | 61 BlockHeader* fNext; ///< doubly-linked list of blocks. |
57 BlockHeader* fPrev; | 62 BlockHeader* fPrev; |
58 int fLiveCount; ///< number of outstanding allocations in the | 63 int fLiveCount; ///< number of outstanding allocations in the |
59 ///< block. | 64 ///< block. |
60 intptr_t fCurrPtr; ///< ptr to the start of blocks free space. | 65 intptr_t fCurrPtr; ///< ptr to the start of blocks free space. |
61 intptr_t fPrevPtr; ///< ptr to the last allocation made | 66 intptr_t fPrevPtr; ///< ptr to the last allocation made |
62 size_t fFreeSize; ///< amount of free space left in the block. | 67 size_t fFreeSize; ///< amount of free space left in the block. |
| 68 size_t fSize; ///< total allocated size of the block |
63 }; | 69 }; |
64 | 70 |
65 enum { | 71 enum { |
66 // We assume this alignment is good enough for everybody. | 72 // We assume this alignment is good enough for everybody. |
67 kAlignment = 8, | 73 kAlignment = 8, |
68 kHeaderSize = GR_CT_ALIGN_UP(sizeof(BlockHeader), kAlignment), | 74 kHeaderSize = GR_CT_ALIGN_UP(sizeof(BlockHeader), kAlignment), |
69 kPerAllocPad = GR_CT_ALIGN_UP(sizeof(BlockHeader*), kAlignment), | 75 kPerAllocPad = GR_CT_ALIGN_UP(sizeof(BlockHeader*), kAlignment), |
70 }; | 76 }; |
| 77 size_t fSize; |
71 size_t fPreallocSize; | 78 size_t fPreallocSize; |
72 size_t fMinAllocSize; | 79 size_t fMinAllocSize; |
73 BlockHeader* fHead; | 80 BlockHeader* fHead; |
74 BlockHeader* fTail; | 81 BlockHeader* fTail; |
75 #ifdef SK_DEBUG | 82 #ifdef SK_DEBUG |
76 int fAllocationCnt; | 83 int fAllocationCnt; |
| 84 int fAllocBlockCnt; |
77 #endif | 85 #endif |
78 }; | 86 }; |
79 | 87 |
80 #endif | 88 #endif |
OLD | NEW |