Move make and destroy to luna
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
1fa99f4f64
commit
a021e7a309
@ -7,16 +7,4 @@ Result<void*> kcalloc(usize nmemb, usize size);
|
|||||||
Result<void*> krealloc(void* ptr, usize size);
|
Result<void*> krealloc(void* ptr, usize size);
|
||||||
Result<void> kfree(void* ptr);
|
Result<void> kfree(void* ptr);
|
||||||
|
|
||||||
template <typename T> Result<T*> make()
|
|
||||||
{
|
|
||||||
void* ptr = TRY(kcalloc(1, sizeof(T)));
|
|
||||||
return new (ptr) T;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T> Result<void> destroy(T* item)
|
|
||||||
{
|
|
||||||
item->~T();
|
|
||||||
return kfree(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void dump_heap_usage();
|
void dump_heap_usage();
|
28
luna/include/luna/Alloc.h
Normal file
28
luna/include/luna/Alloc.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <luna/PlacementNew.h>
|
||||||
|
#include <luna/Result.h>
|
||||||
|
#include <luna/SafeArithmetic.h>
|
||||||
|
|
||||||
|
template <typename T> Result<T*> make()
|
||||||
|
{
|
||||||
|
T* const result = new T;
|
||||||
|
if (!result) return err(ENOMEM);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> Result<T*> make_array(usize count)
|
||||||
|
{
|
||||||
|
T* const result = new T[count];
|
||||||
|
if (!result) return err(ENOMEM);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> void destroy(T* item)
|
||||||
|
{
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> void destroy_array(T* item)
|
||||||
|
{
|
||||||
|
delete[] item;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user