2016-05-31 03:58:58 +00:00
|
|
|
#pragma once
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
#include "common.hpp"
|
2016-06-23 20:26:19 +00:00
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
LEMONBUDDY_NS
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
namespace memory_util {
|
|
|
|
/**
|
|
|
|
* Create a shared pointer using malloc/free
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
inline auto make_malloc_ptr(size_t size = sizeof(T)) {
|
|
|
|
return shared_ptr<T>(static_cast<T*>(malloc(size)), free);
|
|
|
|
}
|
2016-06-23 20:26:19 +00:00
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
/**
|
|
|
|
* Get the number of elements in T
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
inline auto countof(T& p) {
|
|
|
|
return sizeof(p) / sizeof(p[0]);
|
2016-06-23 20:26:19 +00:00
|
|
|
}
|
2016-11-19 03:03:18 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using malloc_ptr_t = shared_ptr<T>;
|
2016-06-23 20:26:19 +00:00
|
|
|
}
|
2016-06-15 03:32:35 +00:00
|
|
|
|
|
|
|
LEMONBUDDY_NS_END
|