lokinet/llarp/mem.hpp

48 lines
730 B
C++
Raw Normal View History

2018-01-26 14:17:51 +00:00
#ifndef LLARP_MEM_HPP
#define LLARP_MEM_HPP
2018-01-29 14:27:24 +00:00
#include <llarp/mem.h>
2018-05-23 20:37:43 +00:00
#include <stdio.h>
namespace llarp
{
template < typename T >
static constexpr size_t
alignment()
{
size_t idx = 0;
size_t sz = sizeof(T);
while(sz)
{
++idx;
sz >>= 1;
}
return 1 << idx;
}
2018-01-31 19:59:26 +00:00
template < typename T >
static T *
Alloc(llarp_alloc *mem)
{
return static_cast< T * >(mem->alloc(mem, sizeof(T), alignment< T >()));
}
2018-05-18 12:39:17 +00:00
void
Zero(void *ptr, size_t sz);
2018-01-26 14:17:51 +00:00
2018-05-23 20:37:43 +00:00
template < typename T >
void
dumphex(const uint8_t *t)
{
size_t idx = 0;
while(idx < sizeof(T))
{
printf("%.2x ", t[idx++]);
if(idx % 8 == 0)
printf("\n");
}
}
} // namespace llarp
2018-05-18 12:39:17 +00:00
2018-01-26 14:17:51 +00:00
#endif