Todox: ai-generated. RAII file-to-memory loader with optional mmap backend.
This class loads a file into memory and provides a stable pointer + length.
Backend options:
- Portable "read-all" into an internal buffer (always available).
- Optional mmap mapping on non-Windows builds
- Warning
- Performance note: This class is designed for sequential processing of the returned data. For best results (especially with mmap + MADV_SEQUENTIAL), treat data() as a forward-only byte stream: read from begin to end without repeated random jumps backwards/forwards.
todos:
- move to alib::files
- change exceptions to ALib or don't throw even.
- use with classes TextFile and TextFileLineReader. Those are using std::basic_istream<CharT,Traits>::getline and that's quite slow
- add option to switch between MADV_SEQUENTIAL and MADV_WILLNEED
Definition at line 46 of file mappedfile.hpp.
|
|
| MappedFile ()=default |
| | Default constructor. Creates an empty view.
|
| | MappedFile (const char *path, std::size_t knownSize=std::numeric_limits< std::size_t >::max(), bool preferMmap=true) |
|
| MappedFile (const MappedFile &)=delete |
| | Deleted copy constructor.
|
|
| MappedFile (MappedFile &&)=delete |
| | Deleted move constructor.
|
| | ~MappedFile () |
| | Destructor. Calls Close.
|
| void | Close () noexcept |
| | Release resources (unmap / free buffer).
|
| bool | IsEmpty () const noexcept |
| bool | IsMMap () const noexcept |
| Data | Open (const char *path, std::size_t knownSize=std::numeric_limits< std::size_t >::max(), bool disableMMap=false) |
|
MappedFile & | operator= (const MappedFile &)=delete |
| | Deleted copy assignment operator.
|
| MappedFile & | operator= (MappedFile &&)=delete |
| std::size_t | Size () const noexcept |