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 2017/07/12 21:41:00 UTC

[jira] [Comment Edited] (ARROW-1210) example does not work

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

Wes McKinney edited comment on ARROW-1210 at 7/12/17 9:40 PM:
--------------------------------------------------------------

hi [~elderrex]

The code you posted is not valid C++. If you want to have a class with builders as members, consider using pointers or smart pointers, e.g. (did not try compiling this code, apologies for any typos):

{code: language=c++}
#include <memory>

#include "arrow/api.h"

using namespace arrow;

struct ArrowBuilder {
  ArrowBuilder() {
    i32_builder.reset(new Int32Builder(default_memory_pool()));
    // etc.
  }

  string type;
  std::unique_ptr<Int32Builder> i32_builder;
  std::unique_ptr<DoubleBuilder> d_builder;
  std::unique_ptr<Int64Builder> i64_builder;
  std::unique_ptr<StringBuilder> s_builder;
};
{code}

You can also stack allocate builders:

{code:language=c++}
void MyFunction(...) {
  Int64Builder i64_builder(default_memory_pool());
}
{code}

We could in theory add default constructors for the builders but right now you need to explicitly pass a memory pool.


was (Author: wesmckinn):
hi [~elderrex]

The code you posted is not valid C++. If you want to have a class with builders as members, consider using pointers or smart pointers, e.g. (did not try compiling this code, apologies for any typos):

{code: language=c++}
#include <memory>

#include "arrow/api.h"

using namespace arrow;

struct ArrowBuilder {
  ArrowBuilder() {
    i32_builder.reset(new Int64Builder(default_memory_pool()));
    // etc.
  }

  string type;
  std::unique_ptr<Int32Builder> i32_builder;
  std::unique_ptr<DoubleBuilder> d_builder;
  std::unique_ptr<Int64Builder> i64_builder;
  std::unique_ptr<StringBuilder> s_builder;
};
{code}

You can also stack allocate builders:

{code:language=c++}
void MyFunction(...) {
  Int64Builder i64_builder(default_memory_pool());
}
{code}

We could in theory add default constructors for the builders but right now you need to explicitly pass a memory pool.

> example does not work
> ---------------------
>
>                 Key: ARROW-1210
>                 URL: https://issues.apache.org/jira/browse/ARROW-1210
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: C++
>            Reporter: yugu
>            Assignee: Wes McKinney
>
> being trying to write something like this
> {code:java}
> #include <arrow/api.h>
> #include <arrow/memory_pool.h>
>         struct ArrowBuilder{
>             string type;
>             ::arrow::Int64Builder i32_builder(::arrow::default_memory_pool());
>             ::arrow::DoubleBuilder d_builder(::arrow::default_memory_pool());
>             ::arrow::Int64Builder i64_builder(::arrow::default_memory_pool());
>             ::arrow::StringBuilder s_builder(::arrow::default_memory_pool());
>         };
> {code}
> kept throwing error: ‘arrow::default_memory_pool’ is not a type



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)