Is there any reasons to not use "mmap" to read files?

user1234 user1234 at 12.de
Sat Feb 12 16:48:26 UTC 2022


On Saturday, 12 February 2022 at 13:17:19 UTC, rempas wrote:
> On Wednesday, 9 February 2022 at 02:07:05 UTC, user1234 wrote:
>>
>> `std.file.readText()` is just fine... your really want to do 
>> an os with call `fgetc` for every single byte that has to be 
>> read ?
>
> Good point! I was really wondering if "fgetc" does a system 
> call every single time that it is called or if the text is 
> buffered just like with "printf". I will use "read" in any case 
> just to be sure tho. I don't want to use Phobos tho so I cannot 
> use "file.readText". Thank you for your time!

I think that nowadays fgetc does not make sense anymore, maybe in 
the past when the amount of memory available was very reduced... 
source files are 100 kb top. You can load 100 of them, the 
fingerprint is still small. What will likely consume the more is 
the AST.

Otherwise readText is easy to translate, it's just fopen then 
fread then fclose, + a few checks for the errors, not a big deal 
to translate.


More information about the Digitalmars-d mailing list