imgref icon indicating copy to clipboard operation
imgref copied to clipboard

Alternative to Vec as backing store?

Open lilith opened this issue 5 years ago • 5 comments

Using SIMD instructions on windows requires allocations be aligned to 16 bytes. Vec does not align to 16 bytes when allocating.

Vec on stable does not permit fallible allocations either, which is critical when allocating large bitmaps.

Would it be possible/practical to allow something other than Vec as a container, or should this be a separate crate?

lilith avatar Oct 22 '20 08:10 lilith

This crate will let you create Img<SomeContainer>, but it may be of limited use. You can create a temporary Img<&[T]> from any container.

I couldn't implement Img<T> where T: AsRef<[Pixel]>, since there's no place to define the pixel type (unconstrained type).

Perhaps it could be solved by defining a VecLike<T> trait to abstract over containers. I'm happy to take PRs for that.

kornelski avatar Oct 22 '20 16:10 kornelski

@lilith How about fixing the issues with Vec instead? Possibly harder to pull off, but benefits everyone!

antonmarsden avatar Oct 22 '20 21:10 antonmarsden

Fallible allocation for Vec has been stalled for years pending other improvements.

Aligned allocation would nearly impossible to insert into Vec ergonomically.

On Thu, Oct 22, 2020, 3:41 PM Anton Marsden [email protected] wrote:

@lilith https://github.com/lilith How about fixing the issues with Vec instead? Possibly harder to pull off, but benefits everyone!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kornelski/imgref/issues/15#issuecomment-714778299, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH4EFK4XPSUDLDAOMRDSMCRH7ANCNFSM4S23KG5Q .

lilith avatar Oct 22 '20 22:10 lilith

@lilith That's unfortunate. I am hoping the allocation API stabilizes eventually so we have more control of (re-)allocation, at least within custom data structures.

antonmarsden avatar Oct 24 '20 00:10 antonmarsden

@lilith I have been building a 2D library (called TooDee, funnily enough) that does allow you wrap a slice and get 2D functionality - take a look at TooDeeViewMut. You'd have to create the aligned slice yourself, obviously.

antonmarsden avatar Oct 24 '20 19:10 antonmarsden