Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ChunkContainer.hpp #152

Merged
merged 8 commits into from
Nov 30, 2024
42 changes: 22 additions & 20 deletions src/XAD/ChunkContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,26 @@ class ChunkContainer
}

ChunkContainer(ChunkContainer&& o) noexcept
: chunkList_(std::move(o.chunkList_)), chunk_(o.chunk_), idx_(o.idx_)
{
: chunkList_(std::move(o.chunkList_)), chunk_(o.chunk_), idx_(o.idx_) {
o.chunk_ = 0;
o.idx_ = 0;
}

ChunkContainer& operator=(ChunkContainer&& o)
{
_free_memory();
chunkList_ = std::move(o.chunkList_);
chunk_ = o.chunk_;
idx_ = o.idx_;
ChunkContainer& operator=(ChunkContainer&& o) noexcept {
if (this != &o) {
_free_memory();
chunkList_ = std::move(o.chunkList_);
chunk_ = o.chunk_;
idx_ = o.idx_;
o.chunk_ = 0;
o.idx_ = 0;
}
return *this;
}

ChunkContainer(const ChunkContainer&) = delete;
auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved
ChunkContainer& operator=(const ChunkContainer&) = delete;

~ChunkContainer() { _free_memory(); }

void reserve(size_type s)
auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved
{
size_type nc = getNumChunks(s);
Expand Down Expand Up @@ -438,21 +440,21 @@ class ChunkContainer
private:
std::vector<char*> chunkList_;
size_type chunk_, idx_;

void check_space()
auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved
{
if (XAD_VERY_LIKELY(chunk_ == chunkList_.size() - 1))
{
char* chunk = reinterpret_cast<char*>(
detail::aligned_alloc(ALIGNMENT, sizeof(value_type) * chunk_size));
if (chunk == NULL)
throw std::bad_alloc();
chunkList_.push_back(chunk);
{
char* chunk = reinterpret_cast<char*>(
detail::aligned_alloc(ALIGNMENT, sizeof(value_type) * chunk_size));
if (chunk == nullptr) {
throw std::bad_alloc();
auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved
}
auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved
++chunk_;
idx_ = 0;
chunkList_.push_back(chunk);
auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved
}
auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved

++chunk_;
idx_ = 0;
}
auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved

auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved
void check_space(size_type i) { reserve(chunk_ * chunk_size + idx_ + i); }

void _free_memory()
Expand Down
Loading