MCPcopy Create free account
hub / github.com/ashvardanian/less_slow.cpp / aligned_array

Class aligned_array

less_slow.cpp:397–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

395 */
396template <typename type_>
397class aligned_array {
398
399 type_ *data_ = nullptr;
400 std::size_t size_ = 0;
401 std::size_t alignment_ = 0;
402
403 public:
404 aligned_array(std::size_t size, std::size_t alignment = 64) : size_(size), alignment_(alignment) {
405 // With `std::aligned_alloc` in C++17, an exception won't be raised, which may be preferred in
406 // some environments. MSVC was late to adopt it, and developers would often use a combination
407 // of lower-level `posix_memalign` and `_aligned_malloc`/`_aligned_free` across Unix and Windows.
408 data_ = (type_ *)::operator new(sizeof(type_) * size_, std::align_val_t(alignment_));
409 }
410 ~aligned_array() noexcept { ::operator delete(data_, sizeof(type_) * size_, std::align_val_t(alignment_)); }
411
412 aligned_array(aligned_array const &) = delete;
413 aligned_array &operator=(aligned_array const &) = delete;
414 aligned_array(aligned_array &&) = delete;
415 aligned_array &operator=(aligned_array &&) = delete;
416
417 type_ *begin() const noexcept { return data_; }
418 type_ *end() const noexcept { return data_ + size_; }
419 type_ &operator[](std::size_t index) noexcept { return data_[index]; }
420 type_ operator[](std::size_t index) const noexcept { return data_[index]; }
421};
422
423static void sorting(bm::State &state) {
424

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected