locked
When does OS reallocate memory RRS feed

  • Question

  • I have read that when we allocate memory virtually or using malloc() the contents can be reallocated from the OS during program execution.

    I would like to know when does this happen.

    Is it safe to have some disk data in a buffer (using createfile function) pass the buffer pointer to another thread and read these data after a while (I don't know how long this is gonna be it depends on data size which is not fixed) or should I use pagelocked memory?


    Amanda
    Tuesday, January 17, 2012 9:52 AM

Answers

  • >The answer is really comforting but I would like an explanation. How are we sure that the data won't be reallocated?

    The whole idea of the OS having virtual memory is to isolate
    applications from having to account for such things.

    If you've successfully malloc'd a lump of memory in a process, it
    isn't going to disappear outside of your control.

    Dave

    • Marked as answer by Amanda.dalton Wednesday, January 18, 2012 4:50 PM
    Tuesday, January 17, 2012 1:53 PM
  • Amanda.dalton wrote:

    The answer is really comforting but I would like an explanation.

    http://en.wikipedia.org/wiki/Virtual_memory


    Igor Tandetnik

    • Marked as answer by Amanda.dalton Wednesday, January 18, 2012 4:50 PM
    Tuesday, January 17, 2012 2:03 PM

All replies

  • I have read that when we allocate memory virtually or using malloc() the contents can be reallocated from the OS during program execution.

    I would like to know when does this happen.

    When it needs to :)

    Is it safe to have some disk data in a buffer (using createfile function) pass the buffer pointer to another thread and read these data after a while

    Yes, it's safe.

    Dave

    Tuesday, January 17, 2012 11:58 AM
  • The answer is really comforting but I would like an explanation. How are we sure that the data won't be reallocated?


    Amanda
    Tuesday, January 17, 2012 1:20 PM
  • >The answer is really comforting but I would like an explanation. How are we sure that the data won't be reallocated?

    The whole idea of the OS having virtual memory is to isolate
    applications from having to account for such things.

    If you've successfully malloc'd a lump of memory in a process, it
    isn't going to disappear outside of your control.

    Dave

    • Marked as answer by Amanda.dalton Wednesday, January 18, 2012 4:50 PM
    Tuesday, January 17, 2012 1:53 PM
  • Amanda.dalton wrote:

    The answer is really comforting but I would like an explanation.

    http://en.wikipedia.org/wiki/Virtual_memory


    Igor Tandetnik

    • Marked as answer by Amanda.dalton Wednesday, January 18, 2012 4:50 PM
    Tuesday, January 17, 2012 2:03 PM