[Bf-blender-cvs] [24284867759] functions: allocate aligned from monotonic allocator

Jacques Lucke noreply at git.blender.org
Wed Aug 7 11:07:09 CEST 2019


Commit: 242848677593743dd612a6446872ed127ab74553
Author: Jacques Lucke
Date:   Wed Aug 7 10:54:01 2019 +0200
Branches: functions
https://developer.blender.org/rB242848677593743dd612a6446872ed127ab74553

allocate aligned from monotonic allocator

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

M	source/blender/blenlib/BLI_monotonic_allocator.hpp

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

diff --git a/source/blender/blenlib/BLI_monotonic_allocator.hpp b/source/blender/blenlib/BLI_monotonic_allocator.hpp
index ceefa1a2b7e..90637fdbe18 100644
--- a/source/blender/blenlib/BLI_monotonic_allocator.hpp
+++ b/source/blender/blenlib/BLI_monotonic_allocator.hpp
@@ -64,6 +64,17 @@ class MonotonicAllocator {
   {
     return ArrayRef<T>((T *)this->allocate(sizeof(T) * length), length);
   }
+
+  void *allocate_aligned(uint size, uint alignment)
+  {
+    BLI_assert(is_power_of_2_i(alignment));
+    uint64_t space = size + alignment - 1;
+    void *ptr = this->allocate(space);
+    void *aligned_ptr = std::align(alignment, size, ptr, space);
+    BLI_assert(aligned_ptr != nullptr);
+    BLI_assert((POINTER_AS_UINT(aligned_ptr) & (alignment - 1)) == 0);
+    return aligned_ptr;
+  }
 };
 
 }  // namespace BLI



More information about the Bf-blender-cvs mailing list