[Bf-blender-cvs] [fc412c78b4b] functions: comment on fixed array allocator

Jacques Lucke noreply at git.blender.org
Mon Jul 8 17:56:41 CEST 2019


Commit: fc412c78b4b000de6a07b165736d118e1ea399d8
Author: Jacques Lucke
Date:   Mon Jul 8 11:08:23 2019 +0200
Branches: functions
https://developer.blender.org/rBfc412c78b4b000de6a07b165736d118e1ea399d8

comment on fixed array allocator

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

M	source/blender/blenlib/BLI_fixed_array_allocator.hpp

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

diff --git a/source/blender/blenlib/BLI_fixed_array_allocator.hpp b/source/blender/blenlib/BLI_fixed_array_allocator.hpp
index 1c7ec0c2ded..83eba60f418 100644
--- a/source/blender/blenlib/BLI_fixed_array_allocator.hpp
+++ b/source/blender/blenlib/BLI_fixed_array_allocator.hpp
@@ -17,6 +17,10 @@ class FixedArrayAllocator {
   uint m_array_length;
 
  public:
+  /**
+   * Create a new allocator that will allocate arrays with the given length (the element size may
+   * vary).
+   */
   FixedArrayAllocator(uint array_length) : m_array_length(array_length)
   {
   }
@@ -30,11 +34,17 @@ class FixedArrayAllocator {
     }
   }
 
+  /**
+   * Get the number of elements in the arrays allocated by this allocator.
+   */
   uint array_size() const
   {
     return m_array_length;
   }
 
+  /**
+   * Allocate an array buffer in which every element has the given size.
+   */
   void *allocate(uint element_size)
   {
     SmallStack<void *> &stack = this->stack_for_element_size(element_size);
@@ -46,22 +56,35 @@ class FixedArrayAllocator {
     return ptr;
   }
 
+  /**
+   * Deallocate an array buffer that has been allocated with this allocator before.
+   */
   void deallocate(void *ptr, uint element_size)
   {
     SmallStack<void *> &stack = this->stack_for_element_size(element_size);
     stack.push(ptr);
   }
 
+  /**
+   * Allocate a new array of the given type.
+   */
   template<typename T> T *allocate()
   {
     return (T *)this->allocate(sizeof(T));
   }
 
+  /**
+   * Deallocate an array of the given type. It has to be allocated with this allocator before.
+   */
   template<typename T> void deallocate(T *ptr)
   {
     return this->deallocate(ptr, sizeof(T));
   }
 
+  /**
+   * A wrapper for allocated arrays so that they will be deallocated automatically when they go out
+   * of scope.
+   */
   template<typename T> class ScopedAllocation {
    private:
     FixedArrayAllocator &m_allocator;
@@ -102,11 +125,19 @@ class FixedArrayAllocator {
     }
   };
 
+  /**
+   * Allocate an array with the given element size. The return value is a wrapper around the
+   * pointer, so that it is automatically deallocated.
+   */
   ScopedAllocation<void> allocate_scoped(uint element_size)
   {
     return ScopedAllocation<void>(*this, this->allocate(element_size), element_size);
   }
 
+  /**
+   * Allocate an array of the given type. The return value is a wrapper around the pointer, so that
+   * it is automatically deallocated.
+   */
   template<typename T> ScopedAllocation<T> allocate_scoped()
   {
     return ScopedAllocation<T>(*this, this->allocate<T>(), sizeof(T));



More information about the Bf-blender-cvs mailing list