VecAlignedOffsetAt
Description
Compute the byte offset of element idx from the start of the vector data buffer. The per-element stride is sizeof(VEC_DATATYPE(v)), a compile-time constant. Because sizeof(T) is always a multiple of _Alignof(T), contiguous elements stay naturally aligned without any padding. The allocator governs only the alignment of the buffer base, never the stride.
Parameters
| Name | Direction | Description |
|---|---|---|
v |
in | Vector to query. |
idx |
in | Element index. |
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Access.h:34:
/// TAGS: Vec, Access, Index
///
#define VecAt(v, idx) ((VEC_DATATYPE(v) *)(VecAlignedOffsetAt((v), (idx)) + (char *)(v)->data))[0]
///
- In
Access.h:45:
/// TAGS: Vec, Access, Index, Pointer
///
#define VecPtrAt(v, idx) ((VEC_DATATYPE(v) *)(VecAlignedOffsetAt((v), (idx)) + (char *)(v)->data))
///
- In
Access.h:84:
/// TAGS: Vec, Access, Iterator, End
///
#define VecEnd(v) ((VEC_DATATYPE(v) *)((char *)(v)->data + VecAlignedOffsetAt((v), (v)->length)))
///
- In
Access.h:93:
/// TAGS: Vec, Access, Size, Bytes
///
#define VecSize(v) VecAlignedOffsetAt(v, (v)->length)
///
- In
Access.h:132:
/// TAGS: Str, Access, Alignment
///
#define StrAlignedOffsetAt(str, idx) VecAlignedOffsetAt(str, idx)
///
- In
VecInt.c:366:
uint16_t idx = extract_u16(data, offset, data_size);
if (idx <= VecLen(vec)) {
volatile uint64_t offset_val = VecAlignedOffsetAt(vec, idx);
(void)offset_val;
}- In
VecCharPtr.c:448:
if (VecLen(vec) > 0 && *offset + 8 <= data_size) {
size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
size_t aligned = VecAlignedOffsetAt(vec, index);
(void)aligned;
}- In
VecStr.c:425:
if (VecLen(vec) > 0 && *offset + 8 <= data_size) {
size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
size_t aligned = VecAlignedOffsetAt(vec, index);
(void)aligned;
}- In
Access.c:195:
vec_size = VecSize(&vec);
vec_len = VecLen(&vec);
size aligned_offset = VecAlignedOffsetAt(&vec, VecLen(&vec));
result = result && (vec_size == aligned_offset);
result = result && (vec_len == VecLen(&vec));- In
Access.c:214:
size aligned_vec_size = VecSize(&aligned_vec);
size aligned_vec_len = VecLen(&aligned_vec);
size aligned_offset_at = VecAlignedOffsetAt(&aligned_vec, VecLen(&aligned_vec));
result = result && (aligned_vec_size == aligned_offset_at);
result = result && (aligned_vec_len == VecLen(&aligned_vec));- In
Access.c:228:
// Test VecAlignedOffsetAt function
bool test_vec_aligned_offset_at(void) {
WriteFmt("Testing VecAlignedOffsetAt\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Access.c:238:
// Check offsets
bool result = (VecAlignedOffsetAt(&vec, 0) == 0);
result = result && (VecAlignedOffsetAt(&vec, 1) == sizeof(int));
result = result && (VecAlignedOffsetAt(&vec, 2) == 2 * sizeof(int));- In
Access.c:239:
// Check offsets
bool result = (VecAlignedOffsetAt(&vec, 0) == 0);
result = result && (VecAlignedOffsetAt(&vec, 1) == sizeof(int));
result = result && (VecAlignedOffsetAt(&vec, 2) == 2 * sizeof(int));- In
Access.c:240:
bool result = (VecAlignedOffsetAt(&vec, 0) == 0);
result = result && (VecAlignedOffsetAt(&vec, 1) == sizeof(int));
result = result && (VecAlignedOffsetAt(&vec, 2) == 2 * sizeof(int));
// Clean up
- In
Access.c:251:
// Stride stays `sizeof(int)` even on an 8-byte-aligned allocator.
result = result && (VecAlignedOffsetAt(&aligned_vec, 0) == 0);
result = result && (VecAlignedOffsetAt(&aligned_vec, 1) == sizeof(int));
result = result && (VecAlignedOffsetAt(&aligned_vec, 2) == 2 * sizeof(int));- In
Access.c:252:
// Stride stays `sizeof(int)` even on an 8-byte-aligned allocator.
result = result && (VecAlignedOffsetAt(&aligned_vec, 0) == 0);
result = result && (VecAlignedOffsetAt(&aligned_vec, 1) == sizeof(int));
result = result && (VecAlignedOffsetAt(&aligned_vec, 2) == 2 * sizeof(int));- In
Access.c:253:
result = result && (VecAlignedOffsetAt(&aligned_vec, 0) == 0);
result = result && (VecAlignedOffsetAt(&aligned_vec, 1) == sizeof(int));
result = result && (VecAlignedOffsetAt(&aligned_vec, 2) == 2 * sizeof(int));
// Clean up
Last updated on