Skip to content

[flexbuffers] Add "AlignedBlob", a version of "Blob" with explicit alignment.#8993

Merged
dbaileychess merged 1 commit into
google:masterfrom
tkoeppe:aligned-blob
Mar 23, 2026
Merged

[flexbuffers] Add "AlignedBlob", a version of "Blob" with explicit alignment.#8993
dbaileychess merged 1 commit into
google:masterfrom
tkoeppe:aligned-blob

Conversation

@tkoeppe
Copy link
Copy Markdown
Contributor

@tkoeppe tkoeppe commented Mar 23, 2026

A blob is an array of bytes and has no intrinsic alignment (i.e. the alignment is 1). The alignment of the existing flexbuffers blob is solely affected by the width of the integer needed to store the blob's size: that integer's width becomes the alignment of the blob.

The proposed AlignedBlob function here piggybacks on this effect and simply uses a user-defined alignment for the width of the integer that stores the blob's size; this automatically imparts that same alignment on the blob itself. (The width is bounded below by the actual width needed to store the blob's size.)

The ability to control the alignment of a blob is important for use cases in which the blob itself stores structured data that we want to access without further copies (e.g. other flatbuffer messages).

@tkoeppe tkoeppe requested a review from dbaileychess as a code owner March 23, 2026 16:38
@github-actions github-actions Bot added the c++ label Mar 23, 2026
@tkoeppe tkoeppe force-pushed the aligned-blob branch 2 times, most recently from 58a18a7 to adb1998 Compare March 23, 2026 16:57
@dbaileychess
Copy link
Copy Markdown
Collaborator

Looks like the failures are real

@tkoeppe
Copy link
Copy Markdown
Contributor Author

tkoeppe commented Mar 23, 2026

@dbaileychess very sorry, a small editor malfunction :-(

…ignment.

A blob is an array of bytes and has no intrinsic alignment (i.e. the
alignment is 1). The alignment of the existing flexbuffers blob is
solely affected by the width of the integer needed to store the blob's
size: that integer's width becomes the alignment of the blob.

The proposed AlignedBlob function here piggybacks on this effect and
simply uses a user-defined alignment for the width of the integer that
stores the blob's size; this automatically imparts that same alignment
on the blob itself. (The width is bounded below by the actual width
needed to store the blob's size.)

The ability to control the alignment of a blob is important for use
cases in which the blob itself stores structured data that we want to
access without further copies (e.g. other flatbuffer messages).
@dbaileychess dbaileychess merged commit 4e582b0 into google:master Mar 23, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants