MCPcopy Create free account
hub / github.com/apache/arrow / EnsureAlignment

Function EnsureAlignment

cpp/src/arrow/util/align_util.cc:149–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147}
148
149Result<std::shared_ptr<Buffer>> EnsureAlignment(std::shared_ptr<Buffer> buffer,
150 int64_t alignment,
151 MemoryPool* memory_pool) {
152 if (alignment == kValueAlignment) {
153 return Status::Invalid(
154 "The kValueAlignment option may only be used to call EnsureAlignment on arrays "
155 "or tables and cannot be used with buffers");
156 }
157 if (alignment <= 0) {
158 return Status::Invalid("Alignment must be a positive integer");
159 }
160 if (!CheckAlignment(*buffer, alignment)) {
161 if (!buffer->is_cpu()) {
162 return Status::NotImplemented("Reallocating an unaligned non-CPU buffer.");
163 }
164 int64_t minimum_desired_alignment = std::max(kDefaultBufferAlignment, alignment);
165 ARROW_ASSIGN_OR_RAISE(
166 auto new_buffer,
167 AllocateBuffer(buffer->size(), minimum_desired_alignment, memory_pool));
168 std::memcpy(new_buffer->mutable_data(), buffer->data(), buffer->size());
169 // R build with openSUSE155 requires an explicit shared_ptr construction
170 return std::shared_ptr<Buffer>(std::move(new_buffer));
171 } else {
172 return buffer;
173 }
174}
175
176Result<std::shared_ptr<ArrayData>> EnsureAlignment(std::shared_ptr<ArrayData> array_data,
177 int64_t alignment,

Callers 5

HandleUnalignedBuffersFunction · 0.85
CreateColumnsMethod · 0.85
TESTFunction · 0.85
TYPED_TESTFunction · 0.85
TEST_FFunction · 0.85

Calls 15

GetTypeForBuffersFunction · 0.85
GetNullCountMethod · 0.80
columnsMethod · 0.80
CheckAlignmentFunction · 0.70
MakeFunction · 0.70
InvalidFunction · 0.50
NotImplementedFunction · 0.50
ARROW_ASSIGN_OR_RAISEFunction · 0.50
MakeArrayFunction · 0.50
mutable_dataMethod · 0.45
dataMethod · 0.45

Tested by 3

TESTFunction · 0.68
TYPED_TESTFunction · 0.68
TEST_FFunction · 0.68