Need help to choose between friendly and unsafe overloads #1094
-
Hello, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Rule no. 1: Don't be scared by the Friendly overloads may use the Ultimately, friendly overloads and the Ultimately the overload you choose is up to you. Friendly overloads are typically preferred by many because they're easier to work with. But (especially when Most of the time, both overloads will have similar performance. But for game development or other applications that require very careful perf considerations, the non-friendly overload is often the better choice for perf because it never allocates memory. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the detailed explanation. I get the point where sometimes, trying to reduce the unsafe context do not bring any advantage.
Time ago I performed a benchmark and saw that passing an existing instance (
I get the point. Trying to avoid fixed statements just to make the code cleaner and more readable can result in access violation exceptions or, even worse, the wrong returned data. I already experienced such things and it's a real nightmare.
I saw such suggestion under Pointer types section, but they probably means exactly what you said.
Given that I can guarantee the required blocks to free the memory, do you see any possible conflicts with how CsWin32 manages the memory? I'm very tempted, but the fact that no one is talking about this class (even in the web) makes me think that there must be a good reason if people still prefer the hardest ways.
As above, you demonstrated me another way on how trying to avoid fixed statements can result in real hell. Thanks for your suggestions. I'm sure it will help lot of people to avoid bad things. I don't want to abuse your time. Unless you feel to add something else, I will close the discussion as resolved. |
Beta Was this translation helpful? Give feedback.
-
Many thanks @AArnott ! Don't want to further abuse your time and I'll close the discussion as resolved. |
Beta Was this translation helpful? Give feedback.
I'm afraid I don't have time or expertise in particular win32 functions to adequately review your code. Sorry.
public unsafe delegate bool SearchQueryDelegate(ReadOnlySpan<char> state, SYSTEM_PROCESS_INFORMATION* processInfo);
You can sometimes avoid the
unsafe
keyword by changing the second parameter from a pointer to aref struct
. In this case that would look likeref SYSTEM_PROCESS_INFORMATION
. Depending on whether the data is already initialized,in
orout
may be more appropriate pa…