Move raw bytes into arraylist

I have an arraylist of structs, which are 10 bytes each.
I saved this arraylist to file using sliceAsBytes.
Now I would like to read the file back into my arraylist. Is that possible?

I implemented the same idea recently (store and load arraylist to file).
Idea is

  • resize arraylist to appropriate size
  • get slice of arraylist’s memory and cast it to bytes using sliceAsBytes.
  • use reader to read into slice of bytes
  • profit
1 Like

There is also simpler option (if you storing just one array in file) to use bytesAsSlice on the file content to get slice of your type. And then use std.array_list.ArrayListAligned.fromOwnedSlice

2 Likes

Ah yes thanks. I got it working. I was on the right path but made a stupid mistake.
Now check if I can read directly from file instead of bytes reading and than copying… I think your suggestion will help.

1 Like