Optimal Buffer size for read-process-write

后端 未结 6 1860
你的背包
你的背包 2020-12-30 05:51

In my function, I need to read some data from a file into a buffer, manipulate the data and write it back to another file. The file is of unknown size and may be very large.

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 06:09

    Memory management is always case dependent and particularly when combined with file I/O.

    There are two possible suggestions from my side.

    1) Use fixed I/O buffer size, e.g. 64K, 256K, 512KB or 1MB. But in this case when there is I/O more than this fixed buffer size, you have to consider offsets to complete I/O in multiple iterations.

    2) Use variable I/O buffer size using malloc(), but this also depends on certain factors. Such as available RAM in your system and maximum dynamic memory allocation limit for process in your OS.

提交回复
热议问题