summaryrefslogtreecommitdiffhomepage
path: root/dev/examples/allocator_system
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-11-17 10:41:20 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-11-17 10:41:20 +0100
commit991379947d661da604dcb662ce325836291f4df3 (patch)
tree8ad57f838ee872c8f48f8a02c11ae45a7fa86399 /dev/examples/allocator_system
parent1d943dcfcddb68f489c126b1e0df41170287e63d (diff)
parent845958a457898343de40ea12953bf9ea3606d69b (diff)
Merge branch 'develop' of github.com:snupowered-oss/scl into snupowered-oss-develop
Diffstat (limited to 'dev/examples/allocator_system')
-rw-r--r--dev/examples/allocator_system/allocator_system.cc13
1 files changed, 8 insertions, 5 deletions
diff --git a/dev/examples/allocator_system/allocator_system.cc b/dev/examples/allocator_system/allocator_system.cc
index 67c3aca..6e7bc6d 100644
--- a/dev/examples/allocator_system/allocator_system.cc
+++ b/dev/examples/allocator_system/allocator_system.cc
@@ -8,10 +8,11 @@
#include <lib/memory/allocator_system.hpp>
#include <iostream>
-struct MyClass
+class MyClass final
{
- int a;
- std::string b;
+public:
+ int a{};
+ std::string b{};
MyClass() : a(0), b("default")
{
@@ -31,17 +32,19 @@ struct MyClass
int main()
{
- using Alloc = ocl::standard_allocator_type<MyClass>;
- Alloc allocator;
+ ocl::standard_allocator_type<MyClass> allocator;
// Test 1: claim() + unclaim()
std::cout << "=== Test 1: claim/unclaim ===\n";
+
MyClass* raw = allocator.claim();
+
std::cout << "raw->a = " << raw->a << ", raw->b = " << raw->b << "\n";
allocator.unclaim(raw); // Manual delete
// Test 2: construct() → shared_ptr
std::cout << "\n=== Test 2: construct (shared_ptr) ===\n";
+
auto ptr = allocator.construct<int, std::string>(42, "hello");
std::cout << "ptr->a = " << ptr->a << ", ptr->b = " << ptr->b << "\n";