1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/Compile.hpp" 6 #include <boost/align/align.hpp> 7 #include <boost/interprocess/sync/file_lock.hpp> 17 namespace hmbdc {
namespace os {
44 template <
typename T,
typename ...Args>
45 T* allocate(
size_t alignment, Args&&... args) {
46 auto cur = boost::alignment::align(alignment,
sizeof(T), cur_, size_);
49 cur_ = ((
char*)cur) +
sizeof(T);
50 res = ::new (cur)T(std::forward<Args>(args)...);
52 res =
static_cast<T*
>(cur);
57 void * memalign(
size_t alignment,
size_t size) {
58 auto res = boost::alignment::align(alignment, size, cur_, size_);
59 cur_ = ((
char*)cur_) + size_;
63 template <
typename T>
void unallocate(T* ptr){
71 void set(
void* base,
size_t size,
bool runCtor =
true) {
94 template <
typename T,
typename ...Args>
95 T* allocate(
size_t alignment, Args&&... args) {
96 std::lock_guard<decltype(lock_)> g(lock_);
97 return BasePtrAllocator::allocate<T>(alignment
98 , std::forward<Args>(args)...);
110 boost::interprocess::file_lock lock_;
123 template <
typename T,
typename ...Args>
124 T* allocate(
size_t alignment, Args&&... args) {
125 std::lock_guard<decltype(lock_)> g(lock_);
126 return BasePtrAllocator::allocate<T>(alignment
127 , std::forward<Args>(args)...);
138 boost::interprocess::file_lock lock_;
149 template <
typename ...NoUses>
152 template <
typename T,
typename ...Args>
153 T* allocate(
size_t alignment, Args&&... args) {
155 auto space = memalign(alignment,
sizeof(T));
156 return new (space) T(std::forward<Args>(args)...);
159 void* memalign(
size_t alignment,
size_t size) {
160 auto res = ::memalign(alignment, size);
162 throw std::bad_alloc();
167 template <
typename T>
174 void free(
void* ptr){
the default vanilla allocate
Definition: Allocators.hpp:145
similar to ShmBasePtrAllocator but using dev memory
Definition: Allocators.hpp:117
helping allocating object and its aggregated objects in a continouse memory
Definition: Allocators.hpp:24
helping allocating object and its aggregated objects in a continouse shared memory ...
Definition: Allocators.hpp:88