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

Avoid additional heap allocation for fields #169

Open
dfordivam opened this issue Jul 5, 2024 · 3 comments
Open

Avoid additional heap allocation for fields #169

dfordivam opened this issue Jul 5, 2024 · 3 comments
Assignees

Comments

@dfordivam
Copy link
Contributor

It may be possible to avoid additional allocation of the fields on heap by making use of APIs like core::ffi::CStr from_bytes_until_nul

let v: Vec<CField> = fields
.iter()
.map(|f| CField {
name: CString::new(f.name).unwrap(),
value: CString::new(f.value).unwrap(),
})
.collect();

Also the unwrap may be avoided on user provided fields, and return an error instead.

@yogh333
Copy link
Contributor

yogh333 commented Aug 30, 2024

Ok but in that case, it means that you must work, at application level, with nul-terminated string with no nul bytes in the middle.

@yogh333 yogh333 self-assigned this Aug 30, 2024
@dfordivam
Copy link
Contributor Author

@yogh333 That is true even right now, unless the unwrap() is removed

@yogh333
Copy link
Contributor

yogh333 commented Sep 10, 2024

@dfordivam No, nowadays you can work with &str or String at application level and Rust SDK will convert them seamlessly into a C compatible string with CString::new. Avoiding additional heap allocation as you propose is thus counter balanced with less comfort at application level, as it implies adding systematically '\0' at the end of every string to be passed to NBGL object to be displayed.

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

2 participants