From 2250678c66cda07caa09aa9ad4d65a8857423692 Mon Sep 17 00:00:00 2001 From: Vladimir Sadovnikov Date: Tue, 14 Nov 2023 01:06:22 +0300 Subject: [PATCH] Implemented advance_ptr function. --- CHANGELOG | 2 +- include/lsp-plug.in/common/alloc.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 8d80b5e..047eea4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,7 +3,7 @@ ******************************************************************************* === 1.0.33 === - +* Implemented advance_ptr function. === 1.0.32 === * Added realloc_aligned function. diff --git a/include/lsp-plug.in/common/alloc.h b/include/lsp-plug.in/common/alloc.h index 1ca0003..43ebeb5 100644 --- a/include/lsp-plug.in/common/alloc.h +++ b/include/lsp-plug.in/common/alloc.h @@ -57,6 +57,15 @@ namespace lsp return static_cast(::malloc(sizeof(T) * count)); } + template + inline T *advance_ptr(P * &ptr, size_t count) + { + uintptr_t x = uintptr_t(ptr); + T *result = reinterpret_cast(ptr); + ptr = reinterpret_cast

(x + count * sizeof(T)); + return result; + } + /** Allocate aligned pointer * * @param ptr reference to pointer to store allocated pointer for future free() operation