Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
2 /*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
10 #ifndef SkChunkAlloc_DEFINED
11 #define SkChunkAlloc_DEFINED
13 #include "SkTypes.h"
15 class SkChunkAlloc : SkNoncopyable {
16 public:
17 SkChunkAlloc(size_t minSize);
18 ~SkChunkAlloc();
20 /**
21 * Free up all allocated blocks. This invalidates all returned
22 * pointers.
23 */
24 void reset();
26 enum AllocFailType {
27 kReturnNil_AllocFailType,
28 kThrow_AllocFailType
29 };
31 void* alloc(size_t bytes, AllocFailType);
32 void* allocThrow(size_t bytes) {
33 return this->alloc(bytes, kThrow_AllocFailType);
34 }
36 /** Call this to unalloc the most-recently allocated ptr by alloc(). On
37 success, the number of bytes freed is returned, or 0 if the block could
38 not be unallocated. This is a hint to the underlying allocator that
39 the previous allocation may be reused, but the implementation is free
40 to ignore this call (and return 0).
41 */
42 size_t unalloc(void* ptr);
44 size_t totalCapacity() const { return fTotalCapacity; }
45 size_t totalUsed() const { return fTotalUsed; }
46 int blockCount() const { return fBlockCount; }
48 /**
49 * Returns true if the specified address is within one of the chunks, and
50 * has at least 1-byte following the address (i.e. if addr points to the
51 * end of a chunk, then contains() will return false).
52 */
53 bool contains(const void* addr) const;
55 private:
56 struct Block;
58 Block* fBlock;
59 size_t fMinSize;
60 size_t fChunkSize;
61 size_t fTotalCapacity;
62 size_t fTotalUsed; // will be <= fTotalCapacity
63 int fBlockCount;
65 Block* newBlock(size_t bytes, AllocFailType ftype);
66 };
68 #endif