From where does the program allocate memory?

后端 未结 4 999
迷失自我
迷失自我 2020-12-18 14:33

As a C and C++ programmer I have used malloc and new to allocate memory. I am just wondering: how does the OS allocate memory?

  1. D

4条回答
  •  青春惊慌失措
    2020-12-18 14:55

    1) Does it allocates from RAM or from hard-disk or from somewhere else?

    On modern systems/platforms supporting virtual memory, the operating system decides where and how to allocate/store the memory. The system is also free to move the memory from one place to another either in ram or on disk.

    2) Can I borrow memory form hard disk just in case ?

    The operating system that manages memory can borrow memory from disk.

    You can also explicitly borrow memory from disk by storing data in a file. C and C++ standard libraries (stdio.h and fstream) enable files manipulation.

提交回复
热议问题