-
Notifications
You must be signed in to change notification settings - Fork 123
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
Consider exposing serialization in public headers #828
Comments
We need to consider a few things before we make this a public interface:
Luckily, the current implementation is header-only (I was wrong earlier), so that's one less thing to worry about. |
For points 3/4 I when working on |
That would imply a memory allocation per displayed type. When implementing the logger, we wanted to implement a poor's man |
I'm not tied to the
If it were a C API would there ever be a need to return anything other than a |
Yes, only enum string representation is const. Most everything else needs to be dynamically constructed (maybe for flags we could precompute all possible combinations, but that's probably too much :-)). I think it would be better to be consistent. Ultimately, I don't think allocating these string is that much of a problem for user-facing APIs. I was mostly worried about blowout of allocations when stringifying complex, possibly nested, structures. But that's only a problem if we were to use something like |
Part of this header could be still in common, unexposed to the user. All Now, if this were to be a C API, and I think it has to be, to be conformant with the rest of the UR API, the new set of functions would require to have either precompiled messages or buffers big enough to store possible strings. The helper functions will be rewritten with char arrays as buffers, replacing current ostream usage. All the reduced memory footprint from having heavy ostream usage would be lost. Maybe the right way would be to expose current operators overload alongside the new C API set of functions and making C and C++ API mutually exclusive during compilation? This would make stream operators not merely a wrapper for a C API, they would still present a more memory-efficient way of printing objects (but when linked as a C++ code only) comparing to char array usage. |
I don't think it's possible to have all the strings precompiled. Unless we just do enums. As for having a preallocated buffer, that could work, but would probably have to be per-thread and be dynamically resizable. Users would have to be aware that calling a
How would you enforce that? With some macros? And why? Even if the two APIs are different, it shouldn't be a problem to have both of them in a program at the same time.
I do think we need a way to implement printing complex structs in a way that doesn't involve doing dozens small short-lived allocations every time. But we can do that entirely on the implementation side (which could leverage the existing C++ code). |
Being able to serialize API objects and functions is something many users of UR are going to want to do, and as it stands they have to do it themselves. We do have pretty much all the enum serialization etc you'd ever need in ur_params.hpp but it isn't a public interface. We should consider moving it out of
common
intoinclude
to allow deduplication of this kind of codeThe text was updated successfully, but these errors were encountered: