3 ms·
As a non-Rust programmer, I'm finding the memory-mapped data example to be very opaque. Does anyone care to explain it?
by skybrian 9y ago
As a non-Rust programmer, I'm finding the memory-mapped data example to be very opaque. Does anyone care to explain it?
- grayrest 9y agoIt's a contrived example and doesn't make a whole lot of sense aside from demonstrating what he means by handle. I'm not an expert but I'll have a go at explaining it. Start at the `Data` struct. It contains a Copy on Write (`CoW`) reference to a vector of bytes (`u8`) with a lifetime labeled `'a`. This is the Handle for the data. You get one by calling `Data::new` and passing in something that can be converted to the CoW. The example is hard coded to work with a vector of u32s (driven by the `Slice<u32>` in `Header`). To use it, you'd call `get_target` with an index and get a u32 back. The other methods on data are doing the pointer math (offset) and casting (`transmute`, `from_raw_parts`) the byte array into a slice of u32s in a safe way. I don't see anything verifying that the byte array passed in is, in fact, a bunch of u32s so I assume that's a given.
- the_mitsuhiko 9y agoIt’s actually a simplifiedversion of what we do. We deal with debug information files and write custom cache files thag look similar to that. https://github.com/getsentry/symbolic/tree/master/symcache/src https://github.com/getsentry/symbolic/tree/master/symcache/s...