Search notes:

Windows - memory

Windows uses a flat address space except for the FS register in x86 and the GS register in x64.

Virtual memory

The virtual memory is a contiguous space of memory (-addresses) that each process sees. Usually, this space is larger than the available physical memory.
A 32-bit process has a virtual address space of up to 4 GB, a 64-bit process up to 8 TB.
The order of addresses in virtual memory does not correspond to the order of addresses in the physical memory.
By default, the lower half of the virtual memory can be used for the data of a process while the upper half is used for Windows. (Only in 32-bit Windows?)
Each process has a page table that maps a process's virtual memory to the physical memory or a page in the paging file.
Because the available physical memory at times cannot cover all required access to virtual memory, the memory manager paging out and in parts of the virtual memory to disk.

Working set

The amount of virtual memory that is currently stored in physical memory is referred to as the working set.

Determining size of memory on the command line

On the command line (cmd.exe, PowerShell), the size of the memory can be determined like so:
C:\> systeminfo | findstr /c:"Total Physical Memory"
The following PowerShell command reports the total physical memory in gigabytes (rounded to one decimal place):
[math]::round( (get-computerInfo).csTotalPhysicalMemory / 1gb, 1 )
The amount of available memory can be determined with
(get-counter '\Memory\Available MBytes').counterSamples
(get-counter '\Memory\Available KBytes').counterSamples
With WMIC.exe:
wmic os get FreePhysicalMemory,FreeSpaceInPagingFiles,FreeVirtualMemory,MaxProcessMemorySize,TotalVirtualMemorySize,TotalVisibleMemorySize

Typeperf

With typeperf.exe, the amount of available memory (bytes) can be shown like so:
C:\> typeperf "\memory\Available Bytes" -sc 1 
Other memory related performance counters can be listed with
typeperf -qx memory

TODO

WinAPI functions HeapAlloc, VirtualAlloc, GlobalAlloc, LocalAlloc, CoTaskMemAlloc; libc functions malloc, free C++ operatior new.
Both, GlobalAlloc and LocalAlloc call HeapAlloc.
In order to share memory across processes, file mapping must be used (CreateFileMapping, OpenFileMapping, MapViewOfFile, …)

See also

Memory page
Memory (general development)
The amount of memory used can be limited in the advanced options of the boot tab of msconfig.exe.
A memory check can be executed by running MdSched.exe.
MdRes.exe
The value of Installed Physical Memory (RAM), Available Physical Memory, Total Virtual Memory and Available Virtual Memory under System Summary in msinfo32.exe as well as the msinfo32.exe subtree Hardware-Resources -> Memory.

Index