Fix evil allocations, marshaling overhead #329
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
StrToPtr() had at least 4 extra allocations of byte[] and char[] arrays that will make Unity's GC and frametime stability sad, taking into account you can updated 5 times per 20 seconds, which is few frames apart.
Also, there was 0 reason to have that marshaling invoke overhead where it zeroes byte by byte in a loop. There is no point, we already overwrite whole memory via .Copy() and we only allocate as much as needed for the string bytes, no extra. No security concerns here.
The only question that eludes me is the limitation of 128 bytes. It was not enforced on managed side in old code, and I could not find anything in native library. So I assume it is enforced on RPC server side then? Either way since limit is 128 bytes aka 128 ASCII characters at min, it makes sense to limit allocated data to 128 chars max to avoid sending perhaps megabytes of mistakenly generated by user string (I assume it will throw in pipe/socket).