summaryrefslogtreecommitdiffhomepage
path: root/dev/lib/memory
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-08-24 14:13:34 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-08-24 14:13:34 +0200
commitb0d0e894a4394eed25dbb5cead12edd08a510a92 (patch)
tree788915894a49d5267391f3bf6b9c41a1c5fe40b8 /dev/lib/memory
parentd02bd0eb656b885bdf48088529183c40df8bd9c1 (diff)
feat! use `chunk_string` in the CGI module. Add additional constructors
for `chunk_string` Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/lib/memory')
-rw-r--r--dev/lib/memory/tracked_ptr.hpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/dev/lib/memory/tracked_ptr.hpp b/dev/lib/memory/tracked_ptr.hpp
index da7e46c..7030f40 100644
--- a/dev/lib/memory/tracked_ptr.hpp
+++ b/dev/lib/memory/tracked_ptr.hpp
@@ -9,7 +9,7 @@
#include <cstddef>
#include <utility>
-#include <memory>
+#include <new>
#include <atomic>
#include <sys/types.h>
@@ -45,19 +45,24 @@ namespace snu::memory
template <typename... U>
void retain(T*& ptr, U&&... args)
{
- ptr = new T(args...);
+ ptr = new T(std::forward<U>(args)...);
if (ptr)
{
++allocated_count_;
+ return;
}
- else
- {
- throw std::bad_alloc();
- }
+
+ throw std::bad_alloc();
+ }
+
+ template <typename... U>
+ void must_retain(T*& ptr, U&&... args) noexcept
+ {
+ this->retain(ptr, args...);
}
- void dispose(T*& ptr)
+ void dispose(T*& ptr) noexcept
{
if (ptr)
{
@@ -96,10 +101,17 @@ namespace snu::memory
{
T* ptr = nullptr;
allocator_.retain(ptr, std::forward<U>(args)...);
+
return ptr;
}
- void dispose(T*& ptr)
+ template <typename... U>
+ T* must_retain(U&&... args) noexcept
+ {
+ return this->retain(std::forward<U>(args)...);
+ }
+
+ void dispose(T*& ptr) noexcept
{
allocator_.dispose(ptr);
}
@@ -190,7 +202,7 @@ namespace snu::memory
}
private:
- T* ptr_ = nullptr;
+ T* ptr_{nullptr};
};
template <typename T>