mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-19 17:21:03 +01:00
got rid of cast to uint64
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* @file utils.cpp
|
||||
* @short utility objects for Receiver
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace sls {
|
||||
|
||||
/*
|
||||
* AlignedData
|
||||
* Aligns data to a given type T with proper alignment
|
||||
* @param data: pointer to data
|
||||
* @param size: size of data to align in bytes
|
||||
*/
|
||||
template <typename T> struct AlignedData {
|
||||
T *aligned_ptr; // aligned data pointer
|
||||
|
||||
AlignedData(char *data, size_t size) {
|
||||
if (reinterpret_cast<uintptr_t>(data) % alignof(uint64_t) == 0) {
|
||||
// If aligned directly cast to pointer
|
||||
aligned_ptr = reinterpret_cast<T *>(data);
|
||||
|
||||
} else {
|
||||
|
||||
auto alignedbuffer = std::aligned_alloc(alignof(T), size);
|
||||
std::memcpy(alignedbuffer, data, size);
|
||||
aligned_ptr = reinterpret_cast<T *>(alignedbuffer);
|
||||
}
|
||||
}
|
||||
|
||||
~AlignedData() { std::free(aligned_ptr); }
|
||||
};
|
||||
|
||||
} // namespace sls
|
||||
Reference in New Issue
Block a user