diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-14 13:12:14 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-14 13:12:14 +0100 |
| commit | 0424f52c142e64cfadaa37288feee775fafc2bf0 (patch) | |
| tree | 8d60109d4a53e1583cefc46a5bd0b8fe6cae7385 /include/ocl | |
| parent | 2448ac2ef13d96e4ef3b7a9a15ef1cfdc2195831 (diff) | |
feat! core: new ocl::allocator API (breaking changes) and example.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'include/ocl')
| -rw-r--r-- | include/ocl/allocator_op.hpp | 37 |
1 files changed, 25 insertions, 12 deletions
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 <typename type> struct global_new_op final { - inline auto operator()() -> type* + using pointer_type = type*; + + auto alloc() -> pointer_type { return new type; } + template <size_t N> + auto array_alloc() -> pointer_type + { + return new type[N]; + } + template <typename... var_type> - inline auto var_alloc(var_type&&... args) -> type* + auto var_alloc(var_type&&... args) -> pointer_type { return new type{std::forward<var_type>(args)...}; } }; - /// @note these are guidelines on deleting a resource template <typename type> - 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 <typename ret_type, typename allocator_new, typename allocator_delete> 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 <typename... var_type> - auto construct(var_type&&... args) -> std::shared_ptr<ret_type> + auto construct_var(var_type... args) { - return std::shared_ptr<ret_type>(alloc_op_.template var_alloc<var_type...>(args...), free_op_); + return std::shared_ptr<ret_type>(allocator_new{}.template var_alloc<var_type...>(std::forward<var_type...>(args)...), allocator_delete{}); } + + template<size_t N> + auto construct_array() + { + return std::shared_ptr<ret_type>(allocator_new{}.template array_alloc<N>(), allocator_delete{}); + } + }; template <typename type> - using allocator = allocator_op<type, global_new_op<type>, global_delete_op<type>>; + using allocator = allocator_op<type, global_new_op<type>, global_array_delete_op<type>>; } // namespace ocl #endif // ifndef __OCL_CORE_ALLOC
\ No newline at end of file |
