1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00
polybar/include/utils/memory.hpp
2016-12-21 23:22:02 +01:00

30 lines
600 B
C++

#pragma once
#include <cstring>
#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(free)>
inline malloc_ptr_t<T> make_malloc_ptr(Deleter deleter = 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