feat: introduce common/memory module#11
Conversation
leaves12138
left a comment
There was a problem hiding this comment.
Thanks for the contribution. I found one correctness issue that should be fixed before merge.
MemorySegment::Compare compares each 8-byte chunk as a native-endian integer. On little-endian platforms this does not preserve lexicographical byte order. For example, [0x01, 0, 0, 0, 0, 0, 0, 0] should compare greater than [0x00, 0x01, 0, 0, 0, 0, 0, 0] byte-wise, but the current implementation reads them as 1 and 256 and returns the opposite result.
Please either compare byte-by-byte, or use an endian-safe/big-endian 8-byte comparison, and add a regression test covering this case.
leaves12138
left a comment
There was a problem hiding this comment.
Re-reviewed the latest update. The previous MemorySegment::Compare correctness blocker is fixed: the 8-byte fast path now compares big-endian values, so lexicographical byte order is preserved on little-endian platforms. I do not see further blockers.
Purpose
No Linked issue.
Introduce
MemorySegment— core memory abstraction wrapping aBytesbuffer with typed get/put operations, bounds checking, and bulk copy/compare support (memory_segment.h/cpp)MemorySegmentUtils— utility functions for cross-segment operations including multi-segment copy, compare, equality check, and hash (memory_segment_utils.h/cpp)Tests
memory_segment_test.cpp— MemorySegment typed read/write, boundary checks, bulk operationsmemory_segment_utils_test.cpp— Multi-segment copy, compare, hash correctnessAPI and Format
Documentation
Generative AI tooling