From 0424f52c142e64cfadaa37288feee775fafc2bf0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 14 Dec 2025 13:12:14 +0100 Subject: feat! core: new ocl::allocator API (breaking changes) and example. Signed-off-by: Amlal El Mahrouss --- include/ocl/allocator_op.hpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/ocl/allocator_op.hpp b/include/ocl/allocator_op.hpp index eff3bac..ed6ae90 100644 --- a/include/ocl/allocator_op.hpp +++ b/include/ocl/allocator_op.hpp @@ -17,34 +17,40 @@ namespace ocl template struct global_new_op final { - inline auto operator()() -> type* + using pointer_type = type*; + + auto alloc() -> pointer_type { return new type; } + template + auto array_alloc() -> pointer_type + { + return new type[N]; + } + template - inline auto var_alloc(var_type&&... args) -> type* + auto var_alloc(var_type&&... args) -> pointer_type { return new type{std::forward(args)...}; } }; - /// @note these are guidelines on deleting a resource template - struct global_delete_op final + struct global_array_delete_op final { - inline auto operator()(type* t) -> void + using pointer_type = type*; + + auto operator()(pointer_type t) -> void { - delete t; + delete[] t; } }; template class allocator_op { - allocator_new alloc_op_{}; - allocator_delete free_op_{}; - public: allocator_op() = default; ~allocator_op() = default; @@ -53,14 +59,21 @@ namespace ocl allocator_op(const allocator_op&) = delete; template - auto construct(var_type&&... args) -> std::shared_ptr + auto construct_var(var_type... args) { - return std::shared_ptr(alloc_op_.template var_alloc(args...), free_op_); + return std::shared_ptr(allocator_new{}.template var_alloc(std::forward(args)...), allocator_delete{}); } + + template + auto construct_array() + { + return std::shared_ptr(allocator_new{}.template array_alloc(), allocator_delete{}); + } + }; template - using allocator = allocator_op, global_delete_op>; + using allocator = allocator_op, global_array_delete_op>; } // namespace ocl #endif // ifndef __OCL_CORE_ALLOC \ No newline at end of file -- cgit v1.2.3