You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "Wes McKinney (JIRA)" <ji...@apache.org> on 2018/09/02 18:08:03 UTC

[jira] [Comment Edited] (ARROW-3157) [C++] Improve buffer creation for typed data

    [ https://issues.apache.org/jira/browse/ARROW-3157?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16601593#comment-16601593 ] 

Wes McKinney edited comment on ARROW-3157 at 9/2/18 6:07 PM:
-------------------------------------------------------------

How about something like this

{code}
template <typename T, typename SizeT>
static std::shared_ptr<Buffer> Wrap(const T* data, SizeT length) {
  return std::make_shared<Buffer>(reinterpret_cast<const uint8_t*>(data),
                                  static_cast<int64_t>(length) * sizeof(SizeT));
}
{code}

So we would write

{code}
auto buf = Buffer::Wrap(data, size);
{code}


was (Author: wesmckinn):
How about something like this

{code}
template <typename T, typename SizeT>
static std::shared_ptr<Buffer> Wrap(const T* data, SizeT length) {
  return std::make_shared<Buffer>(reinterpret_cast<const uint8_t*>(data),
                                  static_cast<int64_t>(length));
}
{code}

So we would write

{code}
auto buf = Buffer::Wrap(data, size);
{code}

> [C++] Improve buffer creation for typed data
> --------------------------------------------
>
>                 Key: ARROW-3157
>                 URL: https://issues.apache.org/jira/browse/ARROW-3157
>             Project: Apache Arrow
>          Issue Type: Improvement
>            Reporter: Philipp Moritz
>            Priority: Major
>
> While looking into [https://github.com/apache/arrow/pull/2481,] I noticed this pattern:
> {code:java}
> const uint8_t* bytes_array = reinterpret_cast<const uint8_t*>(input);
> auto buffer = std::make_shared<Buffer>(bytes_array, sizeof(float)*input_length);{code}
> It's not the end of the world but seems a little verbose to me. It would be great to have something like this:
> {code:java}
> auto buffer = MakeBuffer<float>(input, input_length);{code}
> I couldn't find it, does it already exist somewhere? Any thoughts on the API? Potentially specializations to make a buffer out of a std::vector<T> would also be helpful.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)