[Bf-blender-cvs] [f363ff348c2] functions: remove temporary allocator

Jacques Lucke noreply at git.blender.org
Mon Feb 10 12:43:43 CET 2020


Commit: f363ff348c21802549b5138119b6142f84284707
Author: Jacques Lucke
Date:   Mon Feb 10 12:42:24 2020 +0100
Branches: functions
https://developer.blender.org/rBf363ff348c21802549b5138119b6142f84284707

remove temporary allocator

===================================================================

M	source/blender/blenlib/BLI_allocator.h
M	source/blender/blenlib/BLI_array_cxx.h
D	source/blender/blenlib/BLI_temporary_allocator.h
D	source/blender/blenlib/BLI_temporary_allocator_cxx.h
M	source/blender/blenlib/BLI_vector.h
M	source/blender/blenlib/CMakeLists.txt
D	source/blender/blenlib/intern/BLI_temporary_allocator.cc
M	source/blender/functions/intern/multi_functions/mixed.cc
M	source/blender/functions/intern/multi_functions/surface_hook.cc
M	source/blender/functions/intern/multi_functions/util.h
M	source/blender/functions/intern/node_tree.cc
M	source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
M	source/blender/simulations/bparticles/actions.cpp
M	source/blender/simulations/bparticles/emitters.cpp
M	source/blender/simulations/bparticles/events.cpp
M	source/blender/simulations/bparticles/integrator.cpp
M	source/blender/simulations/bparticles/particle_action.cpp
M	source/blender/simulations/bparticles/particle_function.cpp
M	source/blender/simulations/bparticles/particle_function.hpp
M	source/blender/simulations/bparticles/simulate.cpp

===================================================================

diff --git a/source/blender/blenlib/BLI_allocator.h b/source/blender/blenlib/BLI_allocator.h
index a9fbba63ee3..075c181833c 100644
--- a/source/blender/blenlib/BLI_allocator.h
+++ b/source/blender/blenlib/BLI_allocator.h
@@ -36,7 +36,6 @@
 
 #include "BLI_utildefines.h"
 #include "BLI_math_base.h"
-#include "BLI_temporary_allocator.h"
 
 namespace BLI {
 
@@ -60,11 +59,6 @@ class GuardedAllocator {
   {
     MEM_freeN(ptr);
   }
-
-  uint min_allocated_size() const
-  {
-    return 0;
-  }
 };
 
 /**
@@ -104,109 +98,6 @@ class RawAllocator {
     void *actual_pointer = POINTER_OFFSET(ptr, offset);
     free(actual_pointer);
   }
-
-  uint min_allocated_size() const
-  {
-    return 0;
-  }
-};
-
-/**
- * Use this only under specific circumstances as described in BLI_temporary_allocator.h.
- */
-class TemporaryAllocator {
- public:
-  void *allocate(uint size, const char *UNUSED(name))
-  {
-    return BLI_temporary_allocate(size);
-  }
-
-  void *allocate_aligned(uint size, uint alignment, const char *UNUSED(name))
-  {
-    BLI_assert(alignment <= 64);
-    UNUSED_VARS_NDEBUG(alignment);
-    return BLI_temporary_allocate(size);
-  }
-
-  void deallocate(void *ptr)
-  {
-    BLI_temporary_deallocate(ptr);
-  }
-
-  uint min_allocated_size() const
-  {
-    return BLI_TEMPORARY_MINIMUM_SIZE;
-  }
-};
-
-class AnyAllocator {
- public:
-  class VirtualBase {
-   public:
-    virtual void *allocate(uint size, const char *name) = 0;
-
-    virtual void *allocate_aligned(uint size, uint alignment, const char *name) = 0;
-
-    virtual void deallocate(void *ptr) = 0;
-
-    virtual uint min_allocated_size() const = 0;
-  };
-
-  /**
-   * Only take a reference to the underlying allocator. No ownership is transferred.
-   */
-  AnyAllocator(VirtualBase &base) : m_base(&base)
-  {
-  }
-
-  void *allocate(uint size, const char *name)
-  {
-    return m_base->allocate(size, name);
-  }
-
-  void *allocate_aligned(uint size, uint alignment, const char *name)
-  {
-    return m_base->allocate_aligned(size, alignment, name);
-  }
-
-  void deallocate(void *ptr)
-  {
-    m_base->deallocate(ptr);
-  }
-
-  uint min_allocated_size() const
-  {
-    return m_base->min_allocated_size();
-  }
-
- private:
-  VirtualBase *m_base;
-};
-
-template<typename Allocator> class AnyAllocatorBase : public AnyAllocator::VirtualBase {
- private:
-  Allocator m_allocator;
-
- public:
-  void *allocate(uint size, const char *name) final override
-  {
-    return m_allocator.allocate(size, name);
-  }
-
-  void *allocate_aligned(uint size, uint alignment, const char *name) final override
-  {
-    return m_allocator.allocate_aligned(size, alignment, name);
-  }
-
-  void deallocate(void *ptr) final override
-  {
-    m_allocator.deallocate(ptr);
-  }
-
-  uint min_allocated_size() const final override
-  {
-    return m_allocator.min_allocated_size();
-  }
 };
 
 }  // namespace BLI
diff --git a/source/blender/blenlib/BLI_array_cxx.h b/source/blender/blenlib/BLI_array_cxx.h
index 3c14b5c8e81..adb00c95f28 100644
--- a/source/blender/blenlib/BLI_array_cxx.h
+++ b/source/blender/blenlib/BLI_array_cxx.h
@@ -229,15 +229,6 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ar
   }
 };
 
-/**
- * Use this when the following assumptions hold:
- *   - The number of elements in the array is known.
- *   - The array is usually relatively large (so that it does not fit in inline storage).
- *   - Is used in the scope of some function. So it will be freed soon.
- *   - The scope is not in a recursive function.
- */
-template<typename T> using LargeScopedArray = Array<T, 4, TemporaryAllocator>;
-
 }  // namespace BLI
 
 #endif /* __BLI_ARRAY_CXX_H__ */
diff --git a/source/blender/blenlib/BLI_temporary_allocator.h b/source/blender/blenlib/BLI_temporary_allocator.h
deleted file mode 100644
index 5f0112d5b19..00000000000
--- a/source/blender/blenlib/BLI_temporary_allocator.h
+++ /dev/null
@@ -1,65 +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
- *
- * This allocation method assumes
- *   1. The allocations are short-lived.
- *   2. The total number of allocations is bound by a constant per thread.
- *
- * These two assumptions make it possible to cache and reuse relatively large buffers. They allow
- * to hand out buffers that are much larger than the requested size, without the fear of running
- * out of memory.
- *
- * The assumptions might feel a bit limiting at first, but hold true in many cases. For example,
- * many algorithms need to store temporary data. With this allocator, the allocation can become
- * very cheap for common cases.
- *
- * Many cpu-bound algorithms can benefit from being split up into several stages, whereby the
- * output of one stage is written into an array that is read by the next stage. This makes them
- * easier to debug, profile and optimize. Often a reason this is not done is that the memory
- * allocation might be expensive. The goal of this allocator is to make this a non-issue, by
- * reusing the same long buffers over and over again.
- *
- * All allocated buffers are 64 byte aligned, to make them as reusable as possible.
- * If the requested size is too large, there is a fallback to normal allocation. The allocation
- * overhead is probably very small in these cases anyway.
- *
- * The best way to use this allocator is to use one of the prepared containers like
- * LargeScopedVector and LargeScopedArray.
- */
-
-#ifndef __BLI_TEMPORARY_ALLOCATOR_H__
-#define __BLI_TEMPORARY_ALLOCATOR_H__
-
-#include "BLI_utildefines.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define BLI_TEMPORARY_BUFFER_ALIGNMENT 64
-#define BLI_TEMPORARY_MINIMUM_SIZE (64 * 1024)
-
-void *BLI_temporary_allocate(uint size);
-void BLI_temporary_deallocate(void *buffer);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __BLI_TEMPORARY_ALLOCATOR_H__ */
diff --git a/source/blender/blenlib/BLI_temporary_allocator_cxx.h b/source/blender/blenlib/BLI_temporary_allocator_cxx.h
deleted file mode 100644
index 06159f68059..00000000000
--- a/source/blender/blenlib/BLI_temporary_allocator_cxx.h
+++ /dev/null
@@ -1,38 +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.
- */
-
-#ifndef __BLI_TEMPORARY_ALLOCATOR_CXX_H__
-#define __BLI_TEMPORARY_ALLOCATOR_CXX_H__
-
-/** \file
- * \ingroup bli
- */
-
-#include "BLI_temporary_allocator.h"
-
-namespace BLI {
-
-template<typename T> class MutableArrayRef;
-
-template<typename T> MutableArrayRef<T> temporary_allocate_array(uint size)
-{
-  void *ptr = BLI_temporary_allocate(sizeof(T) * size);
-  return MutableArrayRef<T>((T *)ptr, size);
-}
-
-};  // namespace BLI
-
-#endif /* __BLI_TEMPORARY_ALLOCATOR_CXX_H__ */
diff --git a/source/blender/blenlib/BLI_vector.h b/source/blender/blenlib/BLI_vector.h
index e6b18498053..60251347795 100644
--- a/source/blender/blenlib/BLI_vector.h
+++ b/source/blender/blenlib/BLI_vector.h
@@ -612,10 +612,6 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve
      * reallocation every time even though the min_capacity only increments. */
     min_capacity = power_of_2_max_u(min_capacity);
 
-    /* Use a larger capacity if the allocator cannot allocate small buffers. */
-    uint min_allocation_capacity = m_allocator.min_allocated_size() / sizeof(T);
-    min_capacity = std::max(min_capacity, min_allocation_capacity);
-
     uint size = this->size();
 
     T *new_array = (T *)m_allocator.allocate_aligned(
@@ -661,15 +657,6 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve
 
 #undef UPDATE_VECTOR_SIZE
 
-/**
- * Use this when the following assumptions hold:
- *   - The number of elements in the vector is not known from the beginning.
- *   - The vector is usually relatively large (so that it does not fit in inline storage).
- *   - Is used in the scope of some function. So it will be freed soon.
- *   - The scope is not in a recursive function.
- */
-template<typename T, uint N = 4> using LargeScopedVector = Vector<T, N, TemporaryAllocator>;
-
 /**
  * Use when the vector is used in the local scope of a function. It has a larger inline storage by
  * default to make allocations less likely.
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index ec4a2f0e8c8..61c6090ccac 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -52,7 +52,6 @@ set(SRC
   intern/BLI_memblock.c
   intern/BLI_memiter.c
   intern/BLI_mempool.c
-  intern/BLI_temporary_allocator.cc
   intern/BLI_timer.c
   intern/DLRB_tree.c
   intern/array_store.c
@@ -236,8 +235,6 @@ set(SRC
   BLI_sys_types.h
   BLI_system.h
   BLI_task.h
-  BLI_temporary_allocator.h
-  BLI_temporary_allocator_cxx.h
   BLI_threads.h
   BLI_timecode.h
   BLI_timer.h
diff --git a/source/blender/blenlib/intern/BLI_tempor

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list