-
Notifications
You must be signed in to change notification settings - Fork 89
null termination for strings #148
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
Comments
One issue with this is that Admittedly as well, when I've come across these use cases there has been an alternative approach in using APIs with a length property. |
Great question! Because of the reason you mentioned with As for how to do this, I could imagine a few options:
The former is the more-targeted fix, but the latter would allow more more flexibility for allocating space before or after or putting different allocations in different arenas. I lean toward the former, but I'd be interested if the latter seemed actually useful. |
Strings in the component model are represented as pointers with a length and are allocated into component memory via the cabi_realloc function provided by the component.
When interfacing with APIs that work with "legacy" null-terminated strings, there is a need to perform an additional realloc to add the null termination to the string pointer, which can result in an unnecessary copy.
If, the component model were to explicitly define strings with null terminators for these kinds of legacy API use cases, that would avoid the need for this extra interop work.
It's come up a couple of times for me already now in practical component model workflows. I think it would be useful, but I don't have a very strong opinion on it. I thought it worth discussing as an option.
The text was updated successfully, but these errors were encountered: