lidavidm commented on a change in pull request #12116:
URL: https://github.com/apache/arrow/pull/12116#discussion_r805825245
##########
File path: cpp/src/arrow/array/util.cc
##########
@@ -534,6 +533,152 @@ class NullArrayFactory {
std::shared_ptr<Buffer> buffer_;
};
+// mutable version of NullArrayFactory, i.e. one that doesn't reuse a single
buffer
+class MutableNullArrayFactory {
+ private:
+ Result<std::shared_ptr<Buffer>> CreateZeroByteBuffer(size_t
scalar_size_bytes) const {
+ ARROW_ASSIGN_OR_RAISE(auto buffer,
+ AllocateBuffer(length_ * scalar_size_bytes, pool_));
+ std::memset(buffer->mutable_data(), 0, buffer->size());
+ return std::shared_ptr<Buffer>(std::move(buffer));
+ }
+
+ Result<std::shared_ptr<Buffer>> CreateZeroOffsetBuffer(size_t
index_size_bytes) const {
+ ARROW_ASSIGN_OR_RAISE(auto buffer,
+ AllocateBuffer((length_ + 1) * index_size_bytes,
pool_));
+ std::memset(buffer->mutable_data(), 0, buffer->size());
+ return std::shared_ptr<Buffer>(std::move(buffer));
+ }
+
+ Result<std::shared_ptr<Buffer>> CreateZeroBitBuffer(size_t scalar_size_bits)
const {
+ ARROW_ASSIGN_OR_RAISE(
+ auto buffer,
+ AllocateBuffer(bit_util::BytesForBits(length_ * scalar_size_bits),
pool_));
+ std::memset(buffer->mutable_data(), 0, buffer->size());
+ return std::shared_ptr<Buffer>(std::move(buffer));
+ }
+
+ static Result<std::shared_ptr<Buffer>> CreateEmptyBuffer() { return
AllocateBuffer(0); }
Review comment:
nit: AllocateBuffer(0, pool_)?
##########
File path: cpp/src/arrow/device.h
##########
@@ -223,4 +236,53 @@ class ARROW_EXPORT CPUMemoryManager : public MemoryManager
{
ARROW_EXPORT
std::shared_ptr<MemoryManager> default_cpu_memory_manager();
+/// A memory manager that uses the immutable zeros interface of the given
memory pool,
+/// rather than the normal mutable buffer interface.
+class ARROW_EXPORT CPUImmutableZerosMemoryManager : public MemoryManager {
Review comment:
Additionally, I don't see `is_mutable` overridden. But if it's not
overridden, is it useful to have?
##########
File path: cpp/src/arrow/device.h
##########
@@ -223,4 +236,53 @@ class ARROW_EXPORT CPUMemoryManager : public MemoryManager
{
ARROW_EXPORT
std::shared_ptr<MemoryManager> default_cpu_memory_manager();
+/// A memory manager that uses the immutable zeros interface of the given
memory pool,
+/// rather than the normal mutable buffer interface.
+class ARROW_EXPORT CPUImmutableZerosMemoryManager : public MemoryManager {
Review comment:
Couldn't this be placed inside device.cc instead?
##########
File path: cpp/src/arrow/device.h
##########
@@ -223,4 +236,53 @@ class ARROW_EXPORT CPUMemoryManager : public MemoryManager
{
ARROW_EXPORT
std::shared_ptr<MemoryManager> default_cpu_memory_manager();
+/// A memory manager that uses the immutable zeros interface of the given
memory pool,
+/// rather than the normal mutable buffer interface.
+class ARROW_EXPORT CPUImmutableZerosMemoryManager : public MemoryManager {
Review comment:
We could also check `Buffer::is_mutable` in `CopyBufferTo` instead above.
##########
File path: cpp/src/arrow/array/util.cc
##########
@@ -534,6 +533,152 @@ class NullArrayFactory {
std::shared_ptr<Buffer> buffer_;
};
+// mutable version of NullArrayFactory, i.e. one that doesn't reuse a single
buffer
+class MutableNullArrayFactory {
+ private:
+ Result<std::shared_ptr<Buffer>> CreateZeroByteBuffer(size_t
scalar_size_bytes) const {
+ ARROW_ASSIGN_OR_RAISE(auto buffer,
+ AllocateBuffer(length_ * scalar_size_bytes, pool_));
+ std::memset(buffer->mutable_data(), 0, buffer->size());
+ return std::shared_ptr<Buffer>(std::move(buffer));
+ }
+
+ Result<std::shared_ptr<Buffer>> CreateZeroOffsetBuffer(size_t
index_size_bytes) const {
+ ARROW_ASSIGN_OR_RAISE(auto buffer,
+ AllocateBuffer((length_ + 1) * index_size_bytes,
pool_));
+ std::memset(buffer->mutable_data(), 0, buffer->size());
+ return std::shared_ptr<Buffer>(std::move(buffer));
+ }
+
+ Result<std::shared_ptr<Buffer>> CreateZeroBitBuffer(size_t scalar_size_bits)
const {
+ ARROW_ASSIGN_OR_RAISE(
+ auto buffer,
+ AllocateBuffer(bit_util::BytesForBits(length_ * scalar_size_bits),
pool_));
+ std::memset(buffer->mutable_data(), 0, buffer->size());
+ return std::shared_ptr<Buffer>(std::move(buffer));
+ }
+
+ static Result<std::shared_ptr<Buffer>> CreateEmptyBuffer() { return
AllocateBuffer(0); }
+
+ public:
+ MutableNullArrayFactory(MemoryPool* pool, const std::shared_ptr<DataType>&
type,
+ int64_t length)
+ : pool_(pool), type_(type), length_(length) {}
+
+ Result<std::shared_ptr<ArrayData>> Create() {
+ std::vector<std::shared_ptr<ArrayData>> child_data(type_->num_fields());
+ ARROW_ASSIGN_OR_RAISE(auto validity, CreateZeroBitBuffer(1));
+ out_ = ArrayData::Make(type_, length_, {validity}, child_data, length_, 0);
+ RETURN_NOT_OK(VisitTypeInline(*type_, this));
+ return out_;
+ }
+
+ Status Visit(const NullType&) {
+ out_->buffers.resize(1, nullptr);
Review comment:
Hmm, should this be `out_->buffers.resize(0)` since a NullArray has no
buffers?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]