Rerun C++ SDK
Loading...
Searching...
No Matches
arrow_utils.hpp
1#pragma once
2
3#include <arrow/buffer.h>
4
5// Do not include this file in any public header as we don't want to infect the user's namespace
6// with symbols from arrow.
7// (in order to keep compile times low and avoid potential arrow version conflicts)
8
9namespace rerun {
10 /// Creates an arrow buffer from a vector without allocating new memory.
11 ///
12 /// Newer version of the arrow sdk have this builtin as `arrow::Buffer::FromVector`.
13 template <typename T>
14 inline std::shared_ptr<arrow::Buffer> arrow_buffer_from_vector(std::vector<T> vec) {
15 static_assert(
16 std::is_trivial_v<T>,
17 "Buffer::FromVector can only wrap vectors of trivial objects"
18 );
19
20 if (vec.empty()) {
21 return std::make_shared<arrow::Buffer>(nullptr, 0);
22 }
23
24 auto* data = reinterpret_cast<uint8_t*>(vec.data());
25 auto size_in_bytes = static_cast<int64_t>(vec.size() * sizeof(T));
26 return std::shared_ptr<arrow::Buffer>{
27 new arrow::Buffer{data, size_in_bytes},
28 // Keep the vector's buffer alive inside the shared_ptr's destructor until after we have deleted the Buffer.
29 [vec = std::move(vec)](arrow::Buffer* buffer) { delete buffer; }};
30 }
31
32} // namespace rerun
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
std::shared_ptr< arrow::Buffer > arrow_buffer_from_vector(std::vector< T > vec)
Creates an arrow buffer from a vector without allocating new memory.
Definition arrow_utils.hpp:14