As a part of the effort to enable scripting in shipyard, I was curious if anybody has ever written/used a crate that has a Vec-like struct that can be used to allocate things in contiguous memory, but that allows you to specify the size of the items at runtime, because I have no way of knowing the size at compile time.
I essentially need a
Vec that I can store byte arrays of an arbitrary size in, so instead of running
Vec::new() I would run
Vec::new(size) and it would allow me to shove byte arrays/slices into the vec as long as they were
Has anybody ever seen anything similar to that?
There's the bumpalo crate, which looks like it might be similar.
I don't think that
bumpalo will work because:
- It doesn't guarantee contiguous memory when the arena overflows
- There isn't a
Vec like interface to it that allows indexing into a collection that can contain items of a runtime-determined size
Granted the collection I'm looking for could probably be built on top of
bumpalo just like they implemented
Ooh, I just found
scroll which looks really promising.
@leudz Any thoughts on it. It looks like we could store custom components in a
Vec<u8> and then use
scroll to read and write the custom bytes to/from it.
Edit: actually maybe I'm just shooting in the dark again without fully understanding the needs for the project. I think I'm jumping the gun a little. I'll probably come back to this once I understand the problem a little better.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.