我正在开发数组构建器UnsafeAppend应用程序接口。根据文档中的代码。
arrow::Int64Builder builder;
// Make place for 8 values in total
builder.Resize(8);
builder.UnsafeAppend(1);
builder.UnsafeAppend(2);
builder.UnsafeAppend(3);
builder.UnsafeAppendNull();
builder.UnsafeAppend(5);
builder.UnsafeAppend(6);
builder.UnsafeAppend(7);
builder.UnsafeAppend(8);
std::shared_ptr<arrow::Array> array;
arrow::Status st = builder.Finish(&array);Builder.Resize(i)应该为i值留出空间。在将i更改为另一个值(如100000000 )后,我应该有空间容纳100000000个值。我从我的编译器得到了一个分割错误,这是一个奇怪的问题。我做了另一个实验,将构建器的大小调整为10。构建器应该只有10个空间,但我的代码可以成功地将比10更多的值附加到构建器。
我有点困惑,是不是构建器应该有与api Resize(i)完全相同的空间。有谁知道UnsafeAppend API的正确方法吗?
int row = 100000000
arrow::StringBuilder b1;
b1.Resize(row);
for(int i=0;i<row;i++)
{
std::string str = "test";
b1.UnsafeAppend(str);
}发布于 2020-06-09 05:47:17
Resize(n)为n条目保留空间,但不为字符数据保留空间(这是arrow::StringBuilder::UnsafeAppend所需的)。对于你的例子,我推荐:
int row = 100000000
arrow::StringBuilder b1;
b1.Resize(row);
std::string str = "test";
b1.ReserveData(row * str.size());
for(int i=0;i<row;i++)
{
b1.UnsafeAppend(str);
}https://stackoverflow.com/questions/61852262
复制相似问题