VeloGraphX
High-performance dynamic graph analytics in C++20
Loading...
Searching...
No Matches
aligned_allocator.hpp
Go to the documentation of this file.
1
#pragma once
2
#include <cstddef>
3
#include <cstdlib>
4
#include <new>
5
6
namespace
velographx::memory
{
7
inline
void
*
aligned_allocate
(std::size_t bytes, std::size_t alignment = 64) {
8
#if defined(_MSC_VER)
9
auto
* p = _aligned_malloc(bytes, alignment);
if
(!p)
throw
std::bad_alloc{};
return
p;
10
#else
11
void
* p=
nullptr
;
if
(posix_memalign(&p, alignment, bytes)!=0)
throw
std::bad_alloc{};
return
p;
12
#endif
13
}
14
inline
void
aligned_deallocate
(
void
* p)
noexcept
{
15
#if defined(_MSC_VER)
16
_aligned_free(p);
17
#else
18
std::free(p);
19
#endif
20
}
21
}
// namespace velographx::memory
velographx::memory
Definition
aligned_allocator.hpp:6
velographx::memory::aligned_allocate
void * aligned_allocate(std::size_t bytes, std::size_t alignment=64)
Definition
aligned_allocator.hpp:7
velographx::memory::aligned_deallocate
void aligned_deallocate(void *p) noexcept
Definition
aligned_allocator.hpp:14
include
velographx
memory
aligned_allocator.hpp
Generated by
1.9.8