Skip to content

[C++] BufferReader should zero-copy if and only if given a Buffer, not a pointer and length #37212

@lidavidm

Description

@lidavidm

Describe the enhancement requested

BufferReader can be constructed from a pointer and length:

BufferReader::BufferReader(std::string_view data)
: BufferReader(reinterpret_cast<const uint8_t*>(data.data()),
static_cast<int64_t>(data.size())) {}

In that case, it will happily hand you a Buffer backed by that pointer:

return std::make_shared<Buffer>(data_ + position, nbytes);

However, I don't think the APIs make it clear that this ties the lifetime of any data read from the reader to the lifetime of the input. It would be clearer if it would copy in this case, and require you to explicitly construct BufferReader from a Buffer if you want to enable zero-copy.

Component(s)

C++

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions