You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/mem.hpp

27 lines
456 B
C++

7 years ago
#ifndef LLARP_MEM_HPP
#define LLARP_MEM_HPP
7 years ago
#include <llarp/mem.h>
namespace llarp {
7 years ago
template <typename T>
static constexpr size_t alignment() {
size_t idx = 0;
size_t sz = sizeof(T);
7 years ago
while (sz) {
++idx;
sz >>= 1;
}
return 1 << idx;
7 years ago
}
7 years ago
7 years ago
template <typename T>
6 years ago
static T *Alloc(llarp_alloc *mem) {
return static_cast<T *>(mem->alloc(mem, sizeof(T), alignment<T>()));
7 years ago
}
6 years ago
void Zero(void * ptr, size_t sz);
7 years ago
} // namespace llarp
7 years ago
6 years ago
7 years ago
#endif