Skip to content

Commit

Permalink
Document that get_direct_buffer is not fully aligned
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkelfj committed Oct 25, 2023
1 parent be196ef commit 292e910
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -941,9 +941,10 @@ Namespaces can be long so we optionally use a macro to manage this.
}

/*
* If we retrieved the buffer using `flatcc_builder_finalize_aligned_buffer` or
* `flatcc_builder_get_direct_buffer` the struct should also
* be aligned without subtracting the buffer.
* If we retrieved the buffer using `flatcc_builder_finalize_aligned_buffer`
* the buffer should be correctly aligned. If the simpler
* `flatcc_builder_get_direct_buffer` is used, alignment above 4 bytes is
* not guaranteed.
*/
if (vec & 15) {
printf("warning: buffer not aligned in memory\n");
Expand Down Expand Up @@ -1024,10 +1025,13 @@ to provide a custom emitter and for example emit pages over the network
as soon as they complete rather than merging all pages into a single
buffer using `flatcc_builder_finalize_buffer`, or the simplistic
`flatcc_builder_get_direct_buffer` which returns null if the buffer is
too large. See also documentation comments in [flatcc_builder.h] and
[flatcc_emitter.h]. See also `flatc_builder_finalize_aligned_buffer` in
too large. Note that the direct buffer variant does not guarantee full
alignment above 4 bytes in the current memory location but can be copied
to an aligned location. See also documentation comments in
[flatcc_builder.h] and [flatcc_emitter.h].
See also `flatc_builder_finalize_aligned_buffer` in
`builder.h` and the [Builder Interface Reference] when malloc aligned
buffers are insufficent.
or direct buffers are insufficent.


#include "monster_test_builder.h"
Expand Down
5 changes: 4 additions & 1 deletion include/flatcc/flatcc_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,10 @@ char *flatcc_builder_string_edit(flatcc_builder_t *B);
/*
* Only for use with the default emitter.
*
* Fast acces to small buffers from default emitter.
* Fast acces to small buffers from default emitter where alignment
* above 4 bytes (`sizeof(flatbuffers_uoffset_t)`) is not important.
* The buffer is correctly alignmed internally but the current start
* of the buffer might not be before being copied.
*
* Only valid for default emitters before `flatcc_builder_clear`. The
* return buffer is not valid after a call to `flatcc_builder_reset` or
Expand Down

0 comments on commit 292e910

Please sign in to comment.