hi,
I saw previous discussion about nested flatbuffers, and Wouter mentioned ForceVectorAlignment. So, what is the portable solution to embed a flatbuffers in a vector?
On Thursday, November 24, 2016 at 6:10:03 AM UTC+1, John Wiseman wrote:
hi,
I saw previous discussion about nested flatbuffers, and Wouter mentioned ForceVectorAlignment. So, what is the portable solution to embed a flatbuffers in a vector?I just want to point that flatcc (C interface), does not support forced vector alignment, but it is good to see that it has been added, so flatcc will also support this at some point.
--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.
Bringing this up once again. Can someone explain in some detail the alignment issues with respect to using nested flatbuffers?
Also, mikkelfj@ mentioned"More generally, you can either add a nested flatbuffer using a dedicated API method for this, if the language interface supports it. If so, the nested schema must be visible to the containing schema and the nested buffer will be aligned correctly."Does the C++ api have any special support for nested flatbuffers so that clients don't need to worry about things like alignment.
The fact that the ubyte vector holds data that needs 8-byte alignment will not easily be available.
I think C++ at some point made a change to ensure nested flatbuffers are at least aligned to 8 bytes
It would fail if you have a struct with an alignment larger than 8
Thanks mikkelfj. I have some more questions.
The fact that the ubyte vector holds data that needs 8-byte alignment will not easily be available.When we write the schema for a struct/table, I am assuming the flatbuffers code is able to work out the required alignment for it. Shouldn't it be possible for it to do the same for nested flatbuffers? If not would it be possible to expose the min required alignment for a struct/table?
uint16_t flatcc_builder_get_buffer_alignment(flatcc_builder_t *B); |
It would fail if you have a struct with an alignment larger than 8Under what cases can the required alignment be larger than 8? If I am using the basic types provided by flatbuffers for my struct/table, and force the vector alignment of the nested flatbuffer to be 8, can I be assured it is safe in a cross-platform manner?
When we write the schema for a struct/table, I am assuming the flatbuffers code is able to work out the required alignment for it. Shouldn't it be possible for it to do the same for nested flatbuffers? If not would it be possible to expose the min required alignment for a struct/table?
table foo {
x: ulong;
}
table payload {
body: [ ubyte ];
}
builder.Finish(RootType::Pack(builder, &t, nullptr));
// auto padding = flatbuffers::PaddingBytes(
// builder.GetSize(),
// flatbuffers::AlignOf<flatbuffers::largest_scalar_t>());
auto padding = flatbuffers::PaddingBytes(builder.GetSize(),
builder.GetBufferMinAlignment());
// memset
let->payload->body.resize(builder.GetSize() + padding, 0);
const char *p = reinterpret_cast<const char *>(builder.GetBufferPointer());
std::memcpy(&let->payload->body[0], p, builder.GetSize());
../src/third_party/include/flatbuffers/base.h:162:22: runtime error: load of misaligned address 0x62500000798c for type 'const long unsigned int', which requires 8 byte alignment
0x62500000798c: note: pointer points here
14 00 00 00 a3 f0 78 0b 00 00 00 00 08 00 0c 00 04 00 08 00 08 00 00 00 44 00 00 00 04 00 00 00
^
--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "FlatBuffers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/flatbuffers/GXrn90Ey3ZM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to flatbuffers+unsubscribe@googlegroups.com.