-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve memory management, embrace modern .NET #1469
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
Conversation
|
Great change! (that I meant to do for a long time to remove yet another AssemblyProcessor dependency but never got around to do) One important point though: It would make the code more direct, standard & easy to understand, esp. for people familiar with recent high-perf C# (no need to check how our low-level That's what I initially had in mind when I saw all the new recently |
Ideally yes but there are AV's, this is perhaps a halfway measure to have some checks (right now also but sometimes). Since Stride usually works, can also leave it for now and come back to the AV's later getting rid of |
|
I had |
|
Checked it twice, don't see anything wrong - most changes are mundane. Yet I can't start GameStudio anymore - when it sais Loading scene opening Starbreach there is an AV. |
manio143
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked through the first half of this PR (incl Stride.Graphics) - looks good overall
|
Please note that Vulkan builds are failing - VS by default only builds for D3D11 and you may need to modify |
Remove Read/Write(nint, int), also from SerializationStream. Polyfill with extension methods. Source compatible; binary breaking.
Proper exceptions in new methods; fix messages in others.
Remove manually copied documentation comments in favor of `<inheritdoc/>`.
… buffer. Fixes pre-existing buffer overrun and those introduced by assuming trailing alignment padding.
To account for differences in type/size of equally named parameters.
|
Documented the changes in this PR in the description, since the intent is to merge and continue in a future PR. |
|
I didn't have the time to go through every single change yet, but from what I saw so far it's a great PR! |
PR Details
Migrate away from IL weaving and take the first steps to improve memory management.
The mode of operation has generally been not to rewrite to safe code immediately.
Description
ParameterCollection.CopyTo<T>.ParameterCollection.UpdateLayoutcaused by parameters changing type and size after being initialized. Modified the copy operation to right-size them for every element in the collection, pending fixing of the bug causing the types to differ.Utilitiesmarking most methods in it as obsolete, removeInterop.Unsafe.CopyBlockUnalignedinstead ofUtilities.CopyMemory.fixednullif the array being fixed isnullorempty.array.Lengthif thenullresult offixedis intended when the array isnullor empty.Debug.Assertin some places to verify correctness ofCopyBlockand similar operations.System.IO.Stream:ReadandWritethat takeSpan<byte>as argument.System.IO.Stream; no longer throwInvalidOperationExceptionorEndOfStreamException, but useNotSupportedExceptionandIOException.NativeStreamandNativeMemoryStreamfrom the inheritance graph of StridesStreamtypes.NativeStreamWrapper.SerializationStream.NativeStreamis of typeStream, no longerNativeStreamand is obsoleted in favor of the new propertyUnderlyingStream.UnmanagedMemoryStreamto replace all usage ofNativeMemoryStreamin Stride.BlobStreamnow inherits fromUnmanagedMemoryStreaminstead of fromNativeMemoryStream.virtualmethods inNativeStreamwith extension methods. These are obsolete themselves since they are inefficient.BinarySerializationon grounds that it is inefficent and a very minor benefit to Stride users.Navigation.structtounmanaged.SequenceEqualoverCompareMemory, correctness, code style and use of new language features in particularnintandnuintoverIntPtr.Related Issue
#1461
Motivation and Context
See issue for the motivation for starting this PR. Issues with buffer overruns which have surfaced are hard to fix without tracking of owned memory throughout the code. Hence the scope of this PR is broadened to include basic memory management.
Types of changes
Docs change/ refactoring /dependency upgradeDid not make it into this PR
nint,IntPtr,void*or other unmanaged pointers will be obsoleted in favor or overloads that consistently carry length information, such asMemory<T>andSpan<T>.Checklist
$env:USERPROFILE\.nuget\packageswhich don't exist.