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
7inline 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}
14inline 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
void * aligned_allocate(std::size_t bytes, std::size_t alignment=64)
void aligned_deallocate(void *p) noexcept