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

ARROW-360: C++: Add method to shrink PoolBuffer using realloc #272

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion cpp/src/arrow/buffer.cc
Expand Up @@ -92,7 +92,25 @@ Status PoolBuffer::Reserve(int64_t new_capacity) {
}

Status PoolBuffer::Resize(int64_t new_size) {
RETURN_NOT_OK(Reserve(new_size));
if (new_size > size_) {
RETURN_NOT_OK(Reserve(new_size));
} else {
// Buffer is not growing, so shrink to the requested size without
// excess space.
if (capacity_ != new_size) {
// Buffer hasn't got yet the requested size.
if (new_size == 0) {
pool_->Free(mutable_data_, capacity_);
capacity_ = 0;
mutable_data_ = nullptr;
data_ = nullptr;
} else {
RETURN_NOT_OK(pool_->Reallocate(capacity_, new_size, &mutable_data_));
data_ = mutable_data_;
capacity_ = new_size;
}
}
}
size_ = new_size;
return Status::OK();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/test-util.h
Expand Up @@ -184,7 +184,7 @@ static inline void random_ascii(int n, uint32_t seed, uint8_t* out) {

template <typename T>
void rand_uniform_int(int n, uint32_t seed, T min_value, T max_value, T* out) {
DCHECK(out);
DCHECK(out || (n == 0));
std::mt19937 gen(seed);
std::uniform_int_distribution<T> d(min_value, max_value);
for (int i = 0; i < n; ++i) {
Expand Down