Recent

Author Topic: Pointers, do I really need them?  (Read 2946 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14214
  • Probably until I exterminate Putin.
Re: Pointers, do I really need them?
« Reply #15 on: August 11, 2020, 09:16:26 am »
I can't remember the extent to which mmap is on-demand, or if it pre-reads the entire space.
It is a buffered system. It won't map the whole storage space into memory. It is efficient because it uses exact block size.
That is both on Windows and Unix and can map files which are much larger than available memory.
Specialize a type, not a var.

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: Pointers, do I really need them?
« Reply #16 on: August 11, 2020, 02:29:16 pm »
I can't remember the extent to which mmap is on-demand, or if it pre-reads the entire space.
It works on a page basis, so when you read from the virtual memory, a page fault occurs and when the kernel handles it, it sees that this is a file mapping so it reads exactly that page from the file.

If a page isn't used for a while and the physical memory is needed it will be removed from physical memory, meaning if you read the header once and then only other parts, when the memory is needed the header will simply be thrown out and if you try to read it again it is loaded again. This means it is very fast on often read sections and only needs to load sparsely read sections but only discards already read sections under memory pressure.

On Linux if that page is already in the Kernel cache and you only have read access you get direct read access to the kernels cache buffer, meaning it is not even copied, which makes access to often used files pretty fast

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Pointers, do I really need them?
« Reply #17 on: August 11, 2020, 03:49:39 pm »
So in short, it meets my criterion of not reading the entire file in one fell swoop.

ISTM though that particularly if it supported different file formats, using mmap would mandate using pointers since you'r need to express things like "this structure starts one byte beyond the variable-length header". And OP's question was about whether he really needed pointers (with all that they imply).

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018