You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
z_owned_foo_tfoo=z_foo_new();
if (!z_check(foo)) {
// report failure
}
z_process_foo(z_loan(foo));
z_consume_foo(z_move(foo));
This pattern have several problems:
z_owned_foo_t object is created on stack. If developer wants to have it in heap or static memory, the additional copy is performed. This can be bad for performance on hot path and bad for stack size in restrained environments (embedded)
There is no error value returned. It's impossible to know the reason of the failure
we are obliged to do additional call z_check (sometimes it's inlined, but not always). If this is real function call, this may add bad impact to performance
internally both calls to z_process_foo and z_consume_foo do the check for validity of foo, as on rust size the z_owned_foo_t implemented as Option<Foo>. This also may impact the performance
This solves issues 1,2,3. Regarding issue 4 - the functions whcih are expected to be executed frequently (processing of samples, buffers, etc) should use https://docs.rs/unsafe_unwrap/latest/unsafe_unwrap/ instead of normal one, with panic.
The text was updated successfully, but these errors were encountered:
I have recently switched to zenohc after Python experiments and I agree the current error handling mechanism in zenohc is not very familiar to C/C++ users. Error codes may provide a more familiar error handling besides other problems mentioned above.
Also typedef'ed enums can be more descriptive for error codes compared to plain integers as follows.
Summary of discussion with @yellowhatter , @kydos , @Mallets , @DenisBiryukov91 , @milyin about C API
Problem:
Existing C API follows this pattern:
This pattern have several problems:
z_owned_foo_t
object is created on stack. If developer wants to have it in heap or static memory, the additional copy is performed. This can be bad for performance on hot path and bad for stack size in restrained environments (embedded)z_check
(sometimes it's inlined, but not always). If this is real function call, this may add bad impact to performancez_process_foo
andz_consume_foo
do the check for validity of foo, as on rust size thez_owned_foo_t
implemented asOption<Foo>
. This also may impact the performanceProposed change: follow this pattern
This solves issues 1,2,3. Regarding issue 4 - the functions whcih are expected to be executed frequently (processing of samples, buffers, etc) should use https://docs.rs/unsafe_unwrap/latest/unsafe_unwrap/ instead of normal one, with panic.
The text was updated successfully, but these errors were encountered: