Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize memory allocations for strings with default values #73

Open
mikir opened this issue Feb 17, 2025 · 0 comments
Open

Optimize memory allocations for strings with default values #73

mikir opened this issue Feb 17, 2025 · 0 comments
Milestone

Comments

@mikir
Copy link
Collaborator

mikir commented Feb 17, 2025

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.

@mikir mikir added this to the Backlog milestone Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant