2016-05-31 05:58:58 +02:00
|
|
|
#pragma once
|
2016-05-19 16:41:06 +02:00
|
|
|
|
2017-01-11 05:10:51 +01:00
|
|
|
#include <cstdlib>
|
2016-12-14 15:06:46 +01:00
|
|
|
|
2016-06-15 05:32:35 +02:00
|
|
|
#include "common.hpp"
|
2016-06-23 22:26:19 +02:00
|
|
|
|
2016-11-19 06:22:44 +01:00
|
|
|
POLYBAR_NS
|
2016-05-19 16:41:06 +02:00
|
|
|
|
2016-12-21 23:22:02 +01:00
|
|
|
template <typename T>
|
|
|
|
using malloc_ptr_t = shared_ptr<T>;
|
|
|
|
|
2016-06-15 05:32:35 +02:00
|
|
|
namespace memory_util {
|
|
|
|
/**
|
|
|
|
* Create a shared pointer using malloc/free
|
|
|
|
*/
|
2017-01-11 05:10:51 +01:00
|
|
|
template <typename T, size_t Size = sizeof(T), typename Deleter = decltype(std::free)>
|
|
|
|
inline malloc_ptr_t<T> make_malloc_ptr(Deleter deleter = std::free) {
|
2016-12-21 23:22:02 +01:00
|
|
|
return malloc_ptr_t<T>(static_cast<T*>(calloc(1, Size)), deleter);
|
2016-06-15 05:32:35 +02:00
|
|
|
}
|
2016-06-23 22:26:19 +02:00
|
|
|
|
2016-06-15 05:32:35 +02: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 22:26:19 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-15 05:32:35 +02:00
|
|
|
|
2016-11-19 06:22:44 +01:00
|
|
|
POLYBAR_NS_END
|