Why Zserio parameters are stored as raw pointers in C++? #484
Locked
mikir
announced in
Design Notes
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Zserio parameters in parameterized types are stored in C++ as raw pointers. This decision has been chosen after investigation of the following three different solutions:
Passing by value
This is easy for applications but it would bring significant performance and memory penalties for bigger parameters. Besides of that, it is wrong from Zserio point of view because Zserio allows setting offsets which are stored in parameters. Example:
The offset
header.offset
means thatoffset
field in parameterheader
must be updated within ofBlock
scope. This is of course not possible if parameterheader
is passed by value because only local copy can be updated not originalBlockHeader
.To overcome this, we would have to disable completely offsets which use parameters.
Passing by shared pointers
This seems to be a clear, proper solution but it would bring as well performance and memory penalties. Moreover, this solution would change interface for applications. Because each field can be potentially used as a parameter, it would need to be kept by shared pointer instead of by value, regardless if it used as parameter or not.
This would be possible to improve by global analysis of the schema to detect fields which are used as parameters and only that ones kept by shared pointers. But this approach would lead to surprising interface differences after some changes in schema which introduce new parameters of already existing Zserio types.
Passing by raw pointers
This is not intuitive for developers and very fragile solution which is currently implemented in Zserio. Parameters are stored as raw pointers internally but they are not set by applications in constructors. As a consequence, the following methods must be generated:
initializeChildren()
method which sets parameters for all children of the Zserio object recursivelyinitialize()
method which sets all parameters for the Zserio object and which calls internallyinitializeChildren()
methodBeta Was this translation helpful? Give feedback.
All reactions