#mmaped into vec

12 messages · Page 1 of 1 (latest)

naive granite
#

creating a vec from that is extremely unwise

#

any reason you're not using a crate for that?

#

i'm not all that familiar with mmapping, but what's your reason for using vec?

thick cove
#

Vec::leak ?

naive granite
#

creating a slice would be a lot safer, and many of vec's methods are actually on slice

#

note that using Vec::leak for this is just a roundabout way of using slice::from_raw_parts_mut

#

That doesn't sound right

#

slice::from_raw_parts(mmaped, 16) should create a valid slice (of course you'll still need to bound the lifetime appropriately)

thick cove
#

I think what you want here is to create a slice of &mut [MaybeUninit<u8>]

naive granite
#

i would just avoid creating the vec in the first place. It's a bad idea

#

if you also want to be able to push to the unitialized part of the mmap, you really want to create a wrapper struct around it. And destroy the mmap in its Drop impl etc, etc. I havent looked at the memmap2 crate but i imagine it does something like that