diff --git a/README.md b/README.md index 501f40bb..beae97e7 100644 --- a/README.md +++ b/README.md @@ -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"); @@ -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" diff --git a/include/flatcc/flatcc_builder.h b/include/flatcc/flatcc_builder.h index 2e84d297..dd161272 100644 --- a/include/flatcc/flatcc_builder.h +++ b/include/flatcc/flatcc_builder.h @@ -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