34GrMemoryPool::GrMemoryPool(
size_t preallocSize,
size_t minAllocSize)
39 fDebug->fAllocationCount = 0;
45 SkASSERT(0 == fDebug->fAllocationCount);
53 int n = fDebug->fAllocatedIDs.count();
54 for (
int id : fDebug->fAllocatedIDs) {
56 SkDebugf(
"Leaked %d IDs (in no particular order): %d%s", n,
id, (n == i) ?
"\n" :
"");
58 SkDebugf(
", %d%s",
id, (n == i ?
"\n" :
""));
74 Header*
header =
static_cast<Header*
>(alloc.fBlock->ptr(alloc.fAlignedOffset -
sizeof(Header)));
75 header->fStart = alloc.fStart;
79 alloc.fBlock->setMetadata(alloc.fBlock->metadata() + 1);
81#if defined(SK_SANITIZE_ADDRESS)
83#elif defined(SK_DEBUG)
84 header->fSentinel = SkBlockAllocator::kAssignedMarker;
89 static std::atomic<int> nextID{1};
90 return nextID.fetch_add(1, std::memory_order_relaxed);
94 fDebug->fAllocatedIDs.add(
header->fID);
95 fDebug->fAllocationCount++;
99 return alloc.fBlock->ptr(alloc.fAlignedOffset);
103 Header*
header =
reinterpret_cast<Header*
>(
reinterpret_cast<intptr_t
>(p) -
sizeof(Header));
105#if defined(SK_SANITIZE_ADDRESS)
107#elif defined(SK_DEBUG)
109 header->fSentinel = SkBlockAllocator::kFreedMarker;
113 fDebug->fAllocatedIDs.remove(
header->fID);
114 fDebug->fAllocationCount--;
121 intptr_t alignedOffset = (intptr_t)p - (intptr_t)block;
125 memset(p, 0xDD,
header->fEnd - alignedOffset);
140void GrMemoryPool::validate()
const {
141 fAllocator.validate();
144 for (
const auto*
b : fAllocator.blocks()) {
147 SkASSERT(allocCount == fDebug->fAllocationCount);
148 SkASSERT(fDebug->fAllocationCount == fDebug->fAllocatedIDs.count());
static void sk_asan_poison_memory_region(void const volatile *addr, size_t size)
static void sk_asan_unpoison_memory_region(void const volatile *addr, size_t size)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
void * allocate(size_t size)
static constexpr size_t kAlignment
static std::unique_ptr< GrMemoryPool > Make(size_t preallocSize, size_t minAllocSize)
static constexpr size_t kMinAllocationSize
size_t preallocSize() const
bool release(int start, int end)
void setMetadata(int value)
void releaseBlock(Block *block)
ByteRange allocate(size_t size)
static constexpr int kMaxAllocationSize
Block * owningBlock(const void *ptr, int start)
static const char header[]