Description of contiguous data in flat and segmented buffers.

In flat buffers, all data is contiguous. The Ptr() function always returns a pointer descriptor from the buffer position specified to the end of the data, and the BackPtr() function always returns a pointer descriptor from the beginning of the buffer to the buffer position specified.

In segmented buffers, data is contained in segments and the maximum length of contiguous data is the granularity of the buffer. The extent of contiguous data contained in a segment may vary between a single byte, and the granularity, if the insertion and deletion pattern is arbitrary.

However, the following guarantee is made: if the number of bytes inserted or deleted in all insertion and deletion operations is a multiple of some number n, and the granularity is also a multiple of this number n, then all data extents will be a multiple of n in length. This implies that the Ptr() function, given a buffer position which is a multiple of n, will always return a pointer descriptor referring to at least n bytes.

This property of segmented descriptors is exploited by the CArrayFixBase, CArrayVarBase and CArrayPakBase derived array classes. In these classes, all insertion or deletion operations are always done in terms of the (fixed) length of data stored in the buffer. Therefore, the data for an individual array element is always contiguous.

Related concepts