You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rngxx/src/aligned_ptr.cpp

27 lines
503 B

#include <string>
#include <cstdlib>
#include <mem.h>
template<typename T>
static inline T* not_null(T* ptr)
{
if(!ptr) throw "TODO: Nullptr except";
return ptr;
}
namespace mem
{
void* aligned_ptr<void >::_alloc(usize a, usize s) { return not_null<void>( aligned_alloc(a, s) ); }
void aligned_ptr<void >::_dealloc(void* ptr) { free(ptr); }
}
void test()
{
auto ptr = mem::make_aligned<std::string>("hello");
auto len = ptr->size();
printf("Stirng: %s, %lu\n", ptr->c_str(), (usize)len);
}