| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkChunkAlloc_DEFINED | 10 #ifndef SkChunkAlloc_DEFINED |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * Reset to 0 used bytes preserving as much memory as possible. | 26 * Reset to 0 used bytes preserving as much memory as possible. |
| 27 * This invalidates all returned pointers. | 27 * This invalidates all returned pointers. |
| 28 */ | 28 */ |
| 29 void rewind(); | 29 void rewind(); |
| 30 | 30 |
| 31 enum AllocFailType { | 31 enum AllocFailType { |
| 32 kReturnNil_AllocFailType, | 32 kReturnNil_AllocFailType, |
| 33 kThrow_AllocFailType | 33 kThrow_AllocFailType |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 /** |
| 37 * Allocates a memory block of size bytes. |
| 38 * On success: returns a pointer to beginning of memory block that is |
| 39 * 8 byte aligned. The content of allocated block is not initialized. |
| 40 * On failure: calls abort() if called with kThrow_AllocFailType, |
| 41 * otherwise returns NULL pointer. |
| 42 */ |
| 36 void* alloc(size_t bytes, AllocFailType); | 43 void* alloc(size_t bytes, AllocFailType); |
| 44 |
| 45 /** |
| 46 * Shortcut for calling alloc with kThrow_AllocFailType. |
| 47 */ |
| 37 void* allocThrow(size_t bytes) { | 48 void* allocThrow(size_t bytes) { |
| 38 return this->alloc(bytes, kThrow_AllocFailType); | 49 return this->alloc(bytes, kThrow_AllocFailType); |
| 39 } | 50 } |
| 40 | 51 |
| 41 /** Call this to unalloc the most-recently allocated ptr by alloc(). On | 52 /** Call this to unalloc the most-recently allocated ptr by alloc(). On |
| 42 success, the number of bytes freed is returned, or 0 if the block could | 53 success, the number of bytes freed is returned, or 0 if the block could |
| 43 not be unallocated. This is a hint to the underlying allocator that | 54 not be unallocated. This is a hint to the underlying allocator that |
| 44 the previous allocation may be reused, but the implementation is free | 55 the previous allocation may be reused, but the implementation is free |
| 45 to ignore this call (and return 0). | 56 to ignore this call (and return 0). |
| 46 */ | 57 */ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 69 SkDEBUGCODE(int fBlockCount;) | 80 SkDEBUGCODE(int fBlockCount;) |
| 70 SkDEBUGCODE(size_t fTotalLost;) // will be <= fTotalCapacity | 81 SkDEBUGCODE(size_t fTotalLost;) // will be <= fTotalCapacity |
| 71 | 82 |
| 72 Block* newBlock(size_t bytes, AllocFailType ftype); | 83 Block* newBlock(size_t bytes, AllocFailType ftype); |
| 73 Block* addBlockIfNecessary(size_t bytes, AllocFailType ftype); | 84 Block* addBlockIfNecessary(size_t bytes, AllocFailType ftype); |
| 74 | 85 |
| 75 SkDEBUGCODE(void validate();) | 86 SkDEBUGCODE(void validate();) |
| 76 }; | 87 }; |
| 77 | 88 |
| 78 #endif | 89 #endif |
| OLD | NEW |