aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/gpu/GrMemoryPool.h65
-rw-r--r--tests/GrMemoryPoolTest.cpp77
2 files changed, 0 insertions, 142 deletions
diff --git a/src/gpu/GrMemoryPool.h b/src/gpu/GrMemoryPool.h
index 26a763430f..825b83a1ab 100644
--- a/src/gpu/GrMemoryPool.h
+++ b/src/gpu/GrMemoryPool.h
@@ -121,69 +121,4 @@ protected:
};
};
-/**
- * Variant of GrMemoryPool that can only allocate objects of a single type. It is
- * not as flexible as GrMemoryPool, but it has more convenient allocate() method,
- * and more importantly, it guarantees number of objects that are preallocated at
- * construction or when adding a new memory block. I.e.
- *
- * GrMemoryPool pool(3 * sizeof(T), 1000 * sizeof(T));
- * pool.allocate(sizeof(T));
- * pool.allocate(sizeof(T));
- * pool.allocate(sizeof(T));
- *
- * will preallocate 3 * sizeof(T) bytes and use some of those bytes for internal
- * structures. Because of that, last allocate() call will end up allocating a new
- * block of 1000 * sizeof(T) bytes. In contrast,
- *
- * GrObjectMemoryPool<T> pool(3, 1000);
- * pool.allocate();
- * pool.allocate();
- * pool.allocate();
- *
- * guarantees to preallocate enough memory for 3 objects of sizeof(T), so last
- * allocate() will use preallocated memory and won't cause allocation of a new block.
- *
- * Same thing is true for the second (minAlloc) ctor argument: this class guarantees
- * that a newly added block will have enough space for 1000 objects of sizeof(T), while
- * GrMemoryPool does not.
- */
-template <class T>
-class GrObjectMemoryPool: public GrMemoryPool {
-public:
- /**
- * Preallocates memory for preallocCount objects, and sets new block size to be
- * enough to hold minAllocCount objects.
- */
- GrObjectMemoryPool(size_t preallocCount, size_t minAllocCount)
- : GrMemoryPool(CountToSize(preallocCount),
- CountToSize(SkTMax(minAllocCount, kSmallestMinAllocCount))) {
- }
-
- /**
- * Allocates memory for an object, but doesn't construct or otherwise initialize it.
- * The memory must be freed with release().
- */
- T* allocate() { return static_cast<T*>(GrMemoryPool::allocate(sizeof(T))); }
-
-private:
- constexpr static size_t kTotalObjectSize =
- kPerAllocPad + GR_CT_ALIGN_UP(sizeof(T), kAlignment);
-
- constexpr static size_t CountToSize(size_t count) {
- return kHeaderSize + count * kTotalObjectSize;
- }
-
-public:
- /**
- * Minimum value of minAllocCount constructor argument.
- */
- constexpr static size_t kSmallestMinAllocCount =
- (GrMemoryPool::kSmallestMinAllocSize - kHeaderSize + kTotalObjectSize - 1) /
- kTotalObjectSize;
-};
-
-template <class T>
-constexpr size_t GrObjectMemoryPool<T>::kSmallestMinAllocCount;
-
#endif
diff --git a/tests/GrMemoryPoolTest.cpp b/tests/GrMemoryPoolTest.cpp
index 3df4078db2..bdc5557510 100644
--- a/tests/GrMemoryPoolTest.cpp
+++ b/tests/GrMemoryPoolTest.cpp
@@ -318,80 +318,3 @@ DEF_TEST(GrMemoryPoolAPI, reporter) {
REPORTER_ASSERT(reporter, pool.size() == hugeBlockSize + kMinAllocSize);
}
}
-
-DEF_TEST(GrObjectMemoryPoolAPI, reporter) {
- struct Data {
- int value[5];
- };
- using DataObjectPool = GrObjectMemoryPool<Data>;
- constexpr size_t kSmallestMinAllocCount = DataObjectPool::kSmallestMinAllocCount;
-
- // Allocates objects until pool adds a new block (pool.size() changes).
- // Returns number of objects that fit into the current block (i.e. before pool.size()
- // changed; newly allocated block always ends up with one object allocated from it).
- auto allocateObjects = [](DataObjectPool& pool, AutoPoolReleaser& r) -> size_t {
- size_t count = 0;
- size_t origPoolSize = pool.size();
- while (pool.size() == origPoolSize) {
- r.add(pool.allocate());
- count++;
- }
- return count - 1;
- };
-
- // Effective prealloc space capacity is >= kSmallestMinAllocCount.
- {
- DataObjectPool pool(kSmallestMinAllocCount / 3, 0);
- AutoPoolReleaser r(pool);
-
- size_t preallocCount = allocateObjects(pool, r);
- REPORTER_ASSERT(reporter, preallocCount == kSmallestMinAllocCount);
- }
-
- // Effective prealloc space capacity is >= minAllocCount.
- {
- DataObjectPool pool(kSmallestMinAllocCount, 2 * kSmallestMinAllocCount);
- AutoPoolReleaser r(pool);
-
- size_t preallocCount = allocateObjects(pool, r);
- REPORTER_ASSERT(reporter, preallocCount == 2 * kSmallestMinAllocCount);
- }
-
- // Effective block capacity is >= kSmallestMinAllocCount.
- {
- DataObjectPool pool(kSmallestMinAllocCount, kSmallestMinAllocCount / 2);
- AutoPoolReleaser r(pool);
-
- // Fill prealloc space
- allocateObjects(pool, r);
-
- size_t minAllocCount = 1 + allocateObjects(pool, r);
- REPORTER_ASSERT(reporter, minAllocCount == kSmallestMinAllocCount);
- }
-
- // Pool allocates space for exactly preallocCount objects on creation.
- {
- constexpr size_t kPreallocCount = kSmallestMinAllocCount * 7 / 3;
- DataObjectPool pool(kPreallocCount, 0);
- AutoPoolReleaser r(pool);
-
- size_t preallocCount = allocateObjects(pool, r);
- REPORTER_ASSERT(reporter, preallocCount == kPreallocCount);
- }
-
- // Pool allocates space for minAllocCount objects when it adds a new block.
- {
- constexpr size_t kMinAllocCount = kSmallestMinAllocCount * 11 / 3;
- DataObjectPool pool(0, kMinAllocCount);
- AutoPoolReleaser r(pool);
-
- // Fill prealloc space
- allocateObjects(pool, r);
-
- size_t firstBlockCount = 1 + allocateObjects(pool, r);
- REPORTER_ASSERT(reporter, firstBlockCount == kMinAllocCount);
-
- size_t secondBlockCount = 1 + allocateObjects(pool, r);
- REPORTER_ASSERT(reporter, secondBlockCount == kMinAllocCount);
- }
-}