Consider the following schema:
struct AllocationStruct
{
string stringField;
string defaultStringField = "Structure Default String Field Must Be Longer Than 32 Bytes";
};
Then, the generated data constructor will allocate memory for the default string value:
AllocationStruct::AllocationStruct(const AllocatorType& allocator) noexcept :
stringField(allocator),
defaultStringField(::std::string_view{"Structure Default String Field Must Be Longer Than 32 Bytes"}, allocator)
{}
If such constructed data are used as an input for reading (zserio::read), then the defaultStringField is reallocated and initialized with the new read value. This introduces undesired heap memory fragmantation during reading.
This problem can be probably solved by a new constructor which won't fill default values. However, such constructor can be misused.
In all cases, heap memory fragmantation can be considered as a problem, so we should pay attention to it.
Consider the following schema:
Then, the generated data constructor will allocate memory for the default string value:
If such constructed data are used as an input for reading (
zserio::read), then thedefaultStringFieldis reallocated and initialized with the new read value. This introduces undesired heap memory fragmantation during reading.This problem can be probably solved by a new constructor which won't fill default values. However, such constructor can be misused.
In all cases, heap memory fragmantation can be considered as a problem, so we should pay attention to it.