[Bf-blender-cvs] [58754850ca6] functions: remove unused mempool
Jacques Lucke
noreply at git.blender.org
Sun Aug 25 14:34:54 CEST 2019
Commit: 58754850ca666a824d8ed2c384ec18e3f8dc5115
Author: Jacques Lucke
Date: Sun Aug 25 14:19:31 2019 +0200
Branches: functions
https://developer.blender.org/rB58754850ca666a824d8ed2c384ec18e3f8dc5115
remove unused mempool
===================================================================
D source/blender/blenlib/BLI_mempool.hpp
M source/blender/blenlib/CMakeLists.txt
D tests/gtests/blenlib/BLI_mempool_test.cc
M tests/gtests/blenlib/CMakeLists.txt
===================================================================
diff --git a/source/blender/blenlib/BLI_mempool.hpp b/source/blender/blenlib/BLI_mempool.hpp
deleted file mode 100644
index 4737406576c..00000000000
--- a/source/blender/blenlib/BLI_mempool.hpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/** \file
- * \ingroup bli
- *
- * Use this memory allocator when:
- * - all allocations have the same size
- * - only a single thread allocates from this allocator
- * - all allocated memory should be returned to the system at once
- *
- * The allocator keeps track of all unused allocated chunks
- * in a stack. Allocation pops the top chunk, while deallocation
- * pushes the chunk back to the stack.
- *
- * Memory is never returned to the system in this allocator.
- * If the task requires that to happen, another allocator should be
- * used, so that this allocator can stay simple.
- *
- * allocate: O(1) amortized
- * deallocate: O(1)
- * internal allocations: O(lg n) where n is the number of allocations
- */
-
-#pragma once
-
-#include "BLI_stack.hpp"
-#include "BLI_set.hpp"
-
-namespace BLI {
-
-class MemPool {
- private:
- Stack<void *> m_free_stack;
- Vector<void *> m_start_pointers;
- uint m_element_size;
-
-#ifdef DEBUG
- Set<void *> m_allocated_pointers;
-#endif
-
- public:
- MemPool(uint element_size) : m_element_size(element_size)
- {
- }
-
- MemPool(MemPool &mempool) = delete;
-
- ~MemPool()
- {
- for (void *ptr : m_start_pointers) {
- MEM_freeN(ptr);
- }
- }
-
- /**
- * Get a pointer to an uninitialized memory buffer of the size set in the constructor. The buffer
- * will be invalidated when the MemPool is destroyed.
- */
- void *allocate()
- {
- if (m_free_stack.empty()) {
- this->allocate_more();
- }
- void *ptr = m_free_stack.pop();
-#ifdef DEBUG
- m_allocated_pointers.add_new(ptr);
-#endif
- return ptr;
- }
-
- /**
- * Deallocate a pointer that has been allocated using the same mempool before. The memory won't
- * actually be freed immediatly.
- */
- void deallocate(void *ptr)
- {
-#ifdef DEBUG
- BLI_assert(m_allocated_pointers.contains(ptr));
- m_allocated_pointers.remove(ptr);
-#endif
- m_free_stack.push(ptr);
- }
-
- void print_stats() const
- {
- std::cout << "MemPool at " << (void *)this << std::endl;
- std::cout << " Free Amount: " << m_free_stack.size() << std::endl;
- std::cout << " Allocations: " << m_start_pointers.size() << std::endl;
- }
-
- private:
- void allocate_more()
- {
- uint new_amount = 1 << (m_start_pointers.size() + 4);
- void *ptr = MEM_malloc_arrayN(new_amount, m_element_size, __func__);
-
- for (uint i = 0; i < new_amount; i++) {
- m_free_stack.push((char *)ptr + i * m_element_size);
- }
-
- m_start_pointers.append(ptr);
- }
-};
-
-} /* namespace BLI */
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index d29d3f82107..e4ca4fc0b0e 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -244,7 +244,6 @@ set(SRC
intern/BLI_lazy_init.cpp
BLI_listbase_wrapper.hpp
BLI_math.hpp
- BLI_mempool.hpp
BLI_monotonic_allocator.hpp
BLI_object_pool.hpp
BLI_optional.hpp
diff --git a/tests/gtests/blenlib/BLI_mempool_test.cc b/tests/gtests/blenlib/BLI_mempool_test.cc
deleted file mode 100644
index af16e234d1e..00000000000
--- a/tests/gtests/blenlib/BLI_mempool_test.cc
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "testing/testing.h"
-#include "BLI_mempool.hpp"
-
-using namespace BLI;
-
-TEST(mempool, Test1)
-{
- MemPool mempool(sizeof(int));
- int *a = new (mempool.allocate()) int;
- *a = 3;
- EXPECT_EQ(*a, 3);
- mempool.deallocate(a);
-}
-
-TEST(mempool, Test2)
-{
- MemPool mempool(sizeof(int));
- for (uint i = 0; i < 100000; i++) {
- mempool.allocate();
- }
-}
\ No newline at end of file
diff --git a/tests/gtests/blenlib/CMakeLists.txt b/tests/gtests/blenlib/CMakeLists.txt
index 35ecc77ecf9..b0b072969a4 100644
--- a/tests/gtests/blenlib/CMakeLists.txt
+++ b/tests/gtests/blenlib/CMakeLists.txt
@@ -57,7 +57,6 @@ BLENDER_TEST(BLI_math_base "bf_blenlib")
BLENDER_TEST(BLI_math_color "bf_blenlib")
BLENDER_TEST(BLI_math_geom "bf_blenlib")
BLENDER_TEST(BLI_memiter "bf_blenlib")
-BLENDER_TEST(BLI_mempool "bf_blenlib")
BLENDER_TEST(BLI_multi_vector "bf_blenlib")
BLENDER_TEST(BLI_optional "bf_blenlib")
BLENDER_TEST(BLI_path_util "${BLI_path_util_extra_libs}")
More information about the Bf-blender-cvs
mailing list