-
Notifications
You must be signed in to change notification settings - Fork 3
Optimize memory allocations for strings with default values #73
Copy link
Copy link
Open
Milestone
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels