Is there a way to get a Vec<u8> with an alignment (known at compile time) greater than 1? Preferably, where all subsequent uses of the Vec<u8>, including pushing and drop, are safe and correct. #rustlang (I *think* the answer is no, but it would simplify a problem I have.)
-
Show this thread
-
Replying to @burntsushi5
The default allocator on the platform is *likely* to always give you something 8/16-byte aligned, right? You can replace the global allocator, to be sure. Apart from that I agree with how you see the problem.
2 replies 0 retweets 1 like -
Replying to @neurocrypt
Maybe. Dunno. I would definitely want a guarantee though and do not want to rely on a particular allocator since this is in a library.
1 reply 0 retweets 1 like -
Replying to @burntsushi5
And it has to be a Vec, can it be another type or wrapper?
1 reply 0 retweets 0 likes -
Replying to @neurocrypt
Andrew Gallant Retweeted Andrew Gallant
That's what I was getting at here: https://twitter.com/burntsushi5/status/1254599245480579072 … --- The problem is that you have to write the wrapper with some gnarly unsafe internals that I'm likely to get wrong. But if there's a simpler solution, I'm all ears. :-)
Andrew Gallant added,
1 reply 0 retweets 0 likes -
Replying to @burntsushi5
Allocing a buffer of bytes, that can't be hard :) Only problem is if you want to have the Vec methods. Slice methods we can suppy anywhere. I was thinking that an aligned slice is possible in safe code, of course, so depends on what's needed.https://gist.github.com/7851e7a679b91cd00d5f91816e9092f1 …
1 reply 0 retweets 1 like
Yeah, I need vec methods like push. That might work though. Thanks!
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.