| 40 | |
| 41 | template <typename T> |
| 42 | Status CopyBufferFromVector(const std::vector<T>& values, MemoryPool* pool, |
| 43 | std::shared_ptr<Buffer>* result) { |
| 44 | int64_t nbytes = static_cast<int>(values.size()) * sizeof(T); |
| 45 | |
| 46 | ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateBuffer(nbytes, pool)); |
| 47 | auto immutable_data = reinterpret_cast<const uint8_t*>(values.data()); |
| 48 | std::copy(immutable_data, immutable_data + nbytes, buffer->mutable_data()); |
| 49 | memset(buffer->mutable_data() + nbytes, 0, |
| 50 | static_cast<size_t>(buffer->capacity() - nbytes)); |
| 51 | |
| 52 | *result = std::move(buffer); |
| 53 | return Status::OK(); |
| 54 | } |
| 55 | |
| 56 | // Sets approximately pct_null of the first n bytes in null_bytes to zero |
| 57 | // and the rest to non-zero (true) values. |