istream vs memory mapping a file?

前端 未结 3 1759
生来不讨喜
生来不讨喜 2021-02-02 17:31

I am trying to map a file to memory and then parse line by line- is istream what I should be using?

Is istream the same as mapping a file to memory on Windows? I have h

3条回答
  •  [愿得一人]
    2021-02-02 18:14

    Is istream the same as mapping a file to memory on windows?

    Not exactly. They are not the same in the same sense a "stream" is not a "file".

    Think to a file as a stored sequence, and to a stream as the interface for the "channel" (a stream_buffer) that sequence flows when moving from its store towards the receiving variables.

    Think to a memory mapped file as a "file" that -instead been stored outside the processing unit- is stored in-sync in memory. It has the advantage to be visible as a raw memory buffer being a file. If you want to read it as a stream, the simplest way is probably using a istringstream that has that raw buffer as the place to read from.

提交回复
热议问题