Skia
2DGraphicsLibrary
|
Public Types | |
enum | AllocFailType { kReturnNil_AllocFailType, kThrow_AllocFailType } |
Public Member Functions | |
SkChunkAlloc (size_t minSize) | |
void | reset () |
Free up all allocated blocks. More... | |
void | rewind () |
Reset to 0 used bytes preserving as much memory as possible. More... | |
void * | alloc (size_t bytes, AllocFailType) |
Allocates a memory block of size bytes. More... | |
void * | allocThrow (size_t bytes) |
Shortcut for calling alloc with kThrow_AllocFailType. | |
size_t | unalloc (void *ptr) |
Call this to unalloc the most-recently allocated ptr by alloc(). More... | |
size_t | totalCapacity () const |
size_t | totalUsed () const |
int | blockCount () const |
size_t | totalLost () const |
bool | contains (const void *addr) const |
Returns true if the specified address is within one of the chunks, and has at least 1-byte following the address (i.e. More... | |
Private Member Functions | |
Block * | newBlock (size_t bytes, AllocFailType ftype) |
Block * | addBlockIfNecessary (size_t bytes, AllocFailType ftype) |
void | validate () |
Private Attributes | |
Block * | fBlock |
size_t | fMinSize |
size_t | fChunkSize |
size_t | fTotalCapacity |
size_t | fTotalUsed |
int | fBlockCount |
size_t | fTotalLost |
void* SkChunkAlloc::alloc | ( | size_t | bytes, |
AllocFailType | |||
) |
Allocates a memory block of size bytes.
On success: returns a pointer to beginning of memory block that is 8 byte aligned. The content of allocated block is not initialized. On failure: calls abort() if called with kThrow_AllocFailType, otherwise returns NULL pointer.
bool SkChunkAlloc::contains | ( | const void * | addr | ) | const |
Returns true if the specified address is within one of the chunks, and has at least 1-byte following the address (i.e.
if addr points to the end of a chunk, then contains() will return false).
void SkChunkAlloc::reset | ( | ) |
Free up all allocated blocks.
This invalidates all returned pointers.
void SkChunkAlloc::rewind | ( | ) |
Reset to 0 used bytes preserving as much memory as possible.
This invalidates all returned pointers.
size_t SkChunkAlloc::unalloc | ( | void * | ptr | ) |
Call this to unalloc the most-recently allocated ptr by alloc().
On success, the number of bytes freed is returned, or 0 if the block could not be unallocated. This is a hint to the underlying allocator that the previous allocation may be reused, but the implementation is free to ignore this call (and return 0).