6/21/2023 0 Comments Memory mapped file![]() ![]() So you cannot use this accessor to modify contents of the file.Creates a memory-mapped file from an existing file. The memory represents by the sequence is read-only.Moreover, usage of different sequences obtained from the same source can cause unwanted switches between segments of memory-mapped files. Multiple instances of ReadOnlySequence obtained from single source share the same state and must not be shared across multiple threads.However, this approach will cause allocation of virtual memory for the segment in each thread. Alternatively, you can obtain the source for each thread and use them separately. Instance of ReadOnlySequenceAccessor class is not thread-safe and must not be shared between threads without synchronization.Switching between segments is automatic and doesn't require involvement from API consumer.The size of the segment can be defined as an argument of ReadOnlySequenceAccessor constructor. Virtual memory is allocated only for the segment of file.The implementation provides the following features: ReadOnlySequenceAccessor class can be used to obtain ReadOnlySequence over segments of memory-mapped file. ![]() The only way is to represent memory-mapped file as non-contiguous segments of memory.NET standard library offers ReadOnlySequence data type to work with such structures. As a result, you cannot work with large files via Memory or Span data type. ![]() If file too large then attempt to map the whole file to memory is not possible. This problem can be avoided as described below. If segment is too large then you can get OutOfMemoryException exception. This approach has the main drawback: OS allocates pages of virtual memory for the specified segment of memory-mapped file so Memory can represent contiguous block of memory. This is the main reason to use such representation of memory-mapped file. Compatibility with MemoryĬreateMemoryAccessor extension method creates object of IMappedMemoryOwner interface that provides access to mapped file memory via Memory data type. However, this approach allows to achive zero performance overhead in comparison with other views. The access is unsafe because it is organized through the pointer and bound checks are omitted.
0 Comments
Leave a Reply. |