Sunday, November 18, 2018

How does Windows track in-use Memory Locations?


My understanding of the (basic) definiton of a Memory Leak is a location in memory that has been reserved but the pointer to that memory within the application that reserved the memory has been deleted/lost.


My question is this: in order for Windows (or indeed any operating system) to be aware that memory is still reserved after the destruction of the pointer used to manage that memory inside an application, it must independently track what memory is in use. Where does it do this, and how?


Answer



You are correct - every operating system tracks memory use and allocation separately. This is one of it's vital functions. For many reasons it simply wouldn't make sense to pass complete control over memory to a userland process - security can be pointed out as one example: Your process could store sensitive information in memory, thus Operating system should manage which processes will be allowed to access it.


Generally all operating systems have a sub-system named Memory Management (or Memory Manager in Windows), which keeps track of virtual memory. Another part of the OS, Hardware Abstraction, then maps this virtual memory to physical devices. This, of course, prohibits direct interaction between any user process and physical memory.


Directly interacting with this part of operating system is partially available through public API - see Memory Management Functions for Windows. In Linux there are several ways to access memory, this page would be best way to get started with it.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...