Virtual Memory

后端 未结 5 2052
不思量自难忘°
不思量自难忘° 2020-12-18 06:31

Most of the literature on Virtual Memory point out that the as a Application developer,understanding Virtual Memory can help me in harnessing its powerful capabilities. I ha

5条回答
  •  心在旅途
    2020-12-18 06:37

    It's a bit of a vague question.

    The way you can use virtual memory, is chiefly through the use of memory-mapped files. See the mmap() man page for more details.

    Although, you are probably using it implicitly anyway, as any dynamic library is implemented as a mapped file, and many database libraries use them too.

    The interface to use mapped files from higher level languages is often quite inconvenient, which makes them less useful.

    The chief benefits of using mapped files are:

    • No system call overhead when accessing parts of the file (this actually might be a disadvantage, as a page fault probably has as much overhead anyway, if it happens)
    • No need to copy data from OS buffers to application buffers - this can improve performance
    • Ability to share memory between processes.

    Some drawbacks are:

    • 32-bit machines can run out of address space easily
    • Tricky to handle file extending correctly
    • No easy way to see how many / which pages are currently resident (there may be some ways however)
    • Not good for real-time applications, as a page fault may cause an IO request, which blocks the thread (the file can be locked in memory however, but only if there is enough).

提交回复
热议问题