Ben Kietzman created ARROW-8367:
-----------------------------------

             Summary: [C++] Is FromString(..., pool) worthwhile
                 Key: ARROW-8367
                 URL: https://issues.apache.org/jira/browse/ARROW-8367
             Project: Apache Arrow
          Issue Type: Improvement
          Components: C++
    Affects Versions: 0.16.0
            Reporter: Ben Kietzman
             Fix For: 1.0.0


>From [https://github.com/apache/arrow/pull/6863#discussion_r404913683]

There are currently two overloads of {{Buffer::FromString}}, one which takes an 
rvalue reference to string and another which takes a const reference and a 
MemoryPool. In the former case the string is simply moved into a Buffer 
subclass while in the latter the MemoryPool is used to allocate space into 
which the string's contents are copied, which necessitates bubbling the 
potential allocation failure. This seems gratuitous given we don't use 
{{std::string}} to store large quantities so it should be fine to provide only
{code:java}
  static std::unique_ptr<Buffer> FromString(std::string data); 
{code}
and rely on {{std::string}}'s copy constructor when the argument is not an 
rvalue.

In the case of a {{std::string}} which may/does contain large data and must be 
copied, tracking the copied memory with a MemoryPool does not require a great 
deal of boilerplate:
{code:java}
ARROW_ASSIGN_OR_RAISE(auto buffer,
                      Buffer(large).CopySlice(0, large.size(), pool));
{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to