itinero / reminiscence

A library for cross-platform memory mapping.
MIT License
9 stars 6 forks source link

Add support for creating ArrayBase<T> instances backed by "real" memory-mapped files #19

Closed airbreather closed 5 years ago

airbreather commented 5 years ago

There's going to have to be a bit of refactoring on the Itinero side before this can be used all that effectively, since the only ways Itinero currently lets you create ArrayBase<T> instances seem to be:

I still haven't quite figured out the best approach to integrate this in Itinero, but I think this is solid enough to commit to Reminiscence. My current thought is that RouterDb could have methods like Deserialize / DeserializeAndAddContracted, but which accept file paths instead of arbitrary Streams. The inner types would be updated as appropriate, of course. Still thinking about it, though, since the downside is that we'd either have to accept a lot of code duplication (eww) or add even more weird logic in the existing methods around where they check for non-null "profile" instances...

The way I did this was:

The new array class can work in either of two slightly different ways:

  1. If you just pass in the path to a file, then we interpret it to mean that you want to use the entire file for your data. In this mode, CanResize is true (because we can support that by resizing the file).
  2. If you pass in the path to a file with an offset / length, then we support that too, but CanResize will be false, because resizing could mess up offsets for other readers of the same file.

The weakest part of this one: I'm not 100% sure about the values of FileAccess, FileShare, and MemoryMappedFileAccess that I used here. Maybe we should be a bit more restrictive...