You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/01/07 21:16:44 UTC
arrow git commit: ARROW-360: C++: Add method to shrink PoolBuffer
using realloc
Repository: arrow
Updated Branches:
refs/heads/master 74685f386 -> 7d1f1cf91
ARROW-360: C++: Add method to shrink PoolBuffer using realloc
Added no explicit unit test for this as I want to keep the freedom to
the allocator in the future to advise the PoolBuffer on an acceptable
minimal size. In some cases it might be worth it to occupy a whole
page.
Resizing to a smaller size is tested though, so we already have a unit test ensuring that this code runs smoothly.
Author: Uwe L. Korn <uw...@xhochy.com>
Closes #272 from xhochy/ARROW-360 and squashes the following commits:
f4992ee [Uwe L. Korn] Adjust DCHECK for zero size arrays
040d3b4 [Uwe L. Korn] ARROW-360: C++: Add method to shrink PoolBuffer using realloc
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/7d1f1cf9
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/7d1f1cf9
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/7d1f1cf9
Branch: refs/heads/master
Commit: 7d1f1cf91b798259de18ebd772b213e12a6dd194
Parents: 74685f3
Author: Uwe L. Korn <uw...@xhochy.com>
Authored: Sat Jan 7 16:16:31 2017 -0500
Committer: Wes McKinney <we...@twosigma.com>
Committed: Sat Jan 7 16:16:31 2017 -0500
----------------------------------------------------------------------
cpp/src/arrow/buffer.cc | 20 +++++++++++++++++++-
cpp/src/arrow/test-util.h | 2 +-
2 files changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/7d1f1cf9/cpp/src/arrow/buffer.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/buffer.cc b/cpp/src/arrow/buffer.cc
index 6d55f88..2e64ffd 100644
--- a/cpp/src/arrow/buffer.cc
+++ b/cpp/src/arrow/buffer.cc
@@ -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();
}
http://git-wip-us.apache.org/repos/asf/arrow/blob/7d1f1cf9/cpp/src/arrow/test-util.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/test-util.h b/cpp/src/arrow/test-util.h
index e595749..f2da824 100644
--- a/cpp/src/arrow/test-util.h
+++ b/cpp/src/arrow/test-util.h
@@ -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) {