rusb icon indicating copy to clipboard operation
rusb copied to clipboard

Use ArrayVec rather than Vec for Device ports()

Open raphaelcohn opened this issue 4 years ago • 2 comments

The current code allocates from the heap after already allocating from the stack a suitably sized array. This is inefficient but also unnecessary. Allocating Vecs in library code, as a general principal, should be avoided if at all possible, and, if absolutely necessary, it would be nice to be able to capture failed allocation. It's a long standing source of problems in long-running processes.

raphaelcohn avatar Jul 26 '21 06:07 raphaelcohn

I thinking about this when merge ports method. But as said I want keep dependence small as possible. Use crate for only single function it's too expensive

a1ien avatar Jul 26 '21 09:07 a1ien

Expensive? I don't think you mean that. Admittedly, ArrayVec doesn't yet have a 1.0 release. If you're reluctant to add this, then could you let me pass in a [MaybeUninit; 7] then and pass back the used length?

raphaelcohn avatar Jul 26 '21 16:07 raphaelcohn