How to dynamically expand a Memory Mapped File

后端 未结 5 1937
星月不相逢
星月不相逢 2020-12-09 08:16

I\'ve used C# to solve the following requirement.. - create an app the can receive a lot of data fast - you must be able to analyse the received data while more are incoming

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-09 08:50

    Once you map a file in memory, you cannot increase its size. This is a known limitation of memory mapped files.

    ...you must calculate or estimate the size of the finished file because file mapping objects are static in size; once created, their size cannot be increased or decreased.

    One strategy would be to use chunks stored in non-persisted memory mapped files of a given size, say 1GB or 2GB. You would manage these through a top level ViewAccessor of your own design (probably doing basic passthru of the methods you need from the MemoryMappedViewAccessor).

    Edit: or you could just create a non-persisted memory mapped file of a maximal size you expect to use (say 8GB to start, with a parameter to tune it on start-up of your application) and retrieve MemoryMappedViewAccessor's per logical chunk. The non-persisted file will not use physical resources until each view is requested.

提交回复
热议问题