1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-10-27 05:23:39 -04:00
polybar/include/utils/memory.hpp
2017-01-11 07:17:54 +01:00

30 lines
610 B
C++

#pragma once
#include <cstdlib>
#include "common.hpp"
POLYBAR_NS
template <typename T>
using malloc_ptr_t = shared_ptr<T>;
namespace memory_util {
/**
* Create a shared pointer using malloc/free
*/
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) {
return malloc_ptr_t<T>(static_cast<T*>(calloc(1, Size)), deleter);
}
/**
* Get the number of elements in T
*/
template <typename T>
inline auto countof(T& p) {
return sizeof(p) / sizeof(p[0]);
}
}
POLYBAR_NS_END