GC Free implementation of Enumerate#117
Conversation
The existing implementation filled a list, and then returned an enumerator to that. The list itself is heap allocated, any required resizing will also increase GC pressure. The new implementation implements an enumerator directly on the underlying native Enumerate methods, preventing any GC from happening. The Hid api also returns the new HidEnumerator type directly rather than an interface to prevent boxing.
|
Thank you for the PR. I'm very interested in it 🚀 But bear with me that there will be a lot of questions partly technically and partly more general (which you don't need to answer if you don't want to). Let's start with the non technical questions:
I ask this because it's hard to know how HidApi.Net performs under real world conditions. I have only a minimal pet project which is only using a portion of the available API. Now the more technical questions:
|
|
|
(My apologies i'm packing for holiday and wont respond for a while) |
|
No problem. Have a great time on your holidays 🗺️ Thanks for the detailed answers. Great you choose HidApi.Net for your project. If you are into performance you are welcome to take a look at WCharT.Net. It's a library born from code that was originally part of HidApi.Net and allows to work with WCharT characters from C. Now it is a dependency as I did not find anything similar on nuget and thought it may be helpful for others. I wanted to separate the internal code from the public code to make it easy to see the public API on source code level. So everything in the internal folder is actually For me it is a breaking change because there could already be code that uses the result of Implementing So if we keep In Are you sure the I think it can happen that you pass One thing that just came to my mind: I'm not sure if the code works like intended if the It could perhaps not work as List is doing this: public Enumerator GetEnumerator() => new Enumerator(this);
IEnumerator<T> IEnumerable<T>.GetEnumerator() =>
Count == 0 ? SZGenericArrayEnumerator<T>.Empty :
GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable<T>)this).GetEnumerator();So I wonder what would be a good way forward? The What do you think? Or we create some new class just for enumerating and let the old code be the old code and mark the |
|
Are you still planing to pick this up again? |
|
Closed in favour of #122. |
The existing implementation filled a list, and then returned an enumerator to that.
The list itself is heap allocated, any required resizing will also increase GC pressure.
The new implementation implements an enumerator directly on the underlying native Enumerate methods, preventing any GC from happening. The Hid api also returns the new HidEnumerator type directly rather than an interface to prevent boxing.