Skip to content

Commit 52b3c76

Browse files
committed
Add Reallocate implementation to PyArrowMemoryPool
Change-Id: I649da045944f87571c2b84e0e3f710b93958bd2b
1 parent 113e650 commit 52b3c76

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

cpp/src/arrow/io/io-file-test.cc

+9
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,17 @@ class MyMemoryPool : public MemoryPool {
291291
}
292292

293293
void Free(uint8_t* buffer, int64_t size) override { std::free(buffer); }
294+
294295
Status Reallocate(int64_t old_size, int64_t new_size, uint8_t** ptr) override {
295296
*ptr = reinterpret_cast<uint8_t*>(std::realloc(*ptr, new_size));
297+
298+
if (*ptr == NULL) {
299+
std::stringstream ss;
300+
ss << "realloc of size " << new_size << " failed";
301+
return Status::OutOfMemory(ss.str());
302+
}
303+
304+
296305
return Status::OK();
297306
}
298307

python/src/pyarrow/common.cc

+14
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ class PyArrowMemoryPool : public arrow::MemoryPool {
4747
return Status::OK();
4848
}
4949

50+
Status Reallocate(int64_t old_size, int64_t new_size, uint8_t** ptr) override {
51+
*ptr = reinterpret_cast<uint8_t*>(std::realloc(*ptr, new_size));
52+
53+
if (*ptr == NULL) {
54+
std::stringstream ss;
55+
ss << "realloc of size " << new_size << " failed";
56+
return Status::OutOfMemory(ss.str());
57+
}
58+
59+
bytes_allocated_ += new_size - old_size;
60+
61+
return Status::OK();
62+
}
63+
5064
int64_t bytes_allocated() const override {
5165
std::lock_guard<std::mutex> guard(pool_lock_);
5266
return bytes_allocated_;

0 commit comments

Comments
 (0)