Skip to content

Commit

Permalink
Implemented advance_ptr function.
Browse files Browse the repository at this point in the history
  • Loading branch information
sadko4u committed Nov 13, 2023
1 parent 032f645 commit 2250678
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*******************************************************************************

=== 1.0.33 ===

* Implemented advance_ptr function.

=== 1.0.32 ===
* Added realloc_aligned function.
Expand Down
9 changes: 9 additions & 0 deletions include/lsp-plug.in/common/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ namespace lsp
return static_cast<T *>(::malloc(sizeof(T) * count));
}

template <class T, class P>
inline T *advance_ptr(P * &ptr, size_t count)
{
uintptr_t x = uintptr_t(ptr);
T *result = reinterpret_cast<T *>(ptr);
ptr = reinterpret_cast<P *>(x + count * sizeof(T));
return result;
}

/** Allocate aligned pointer
*
* @param ptr reference to pointer to store allocated pointer for future free() operation
Expand Down

0 comments on commit 2250678

Please sign in to comment.