+ 1
Virtual memory verification
Hi I was asked to verify the concept that we do have virtual memory. To prove that , I thought we will have process memory allocated, but how to get this idea. If this is known , should I create large class objects which need more than available memory. Any suggestions are most welcome.
5 Respuestas
+ 4
Ketan Lalcheta it's simple: just ask the OS for process info.
In Windows you can determine virtual memory used for a process by calling the OS API GetProcessMemory and then read the PagefileUsage counter.
In Linux you can read the process status file to get amount of virtual memory used.
Here is example code for Linux that runs on Sololearn. (For my own convenience, this was mostly generated by ChatGPT):
https://sololearn.com/compiler-playground/cfrVC74i4SNb/?ref=app
+ 3
You would need to compile and run the test program on a local machine where you know how much physical memory is installed (as opposed to here which runs on Sololearn servers).
From there, you could create a filler class, use sizeof() to measure how many bytes it needs, then create an array of that class such that the total size would be bigger than either:
A) Max physical memory allocatable per process
B) Total physical memory available
+ 3
Time out max for sololearn like what BroFar said
https://sololearn.com/compiler-playground/cuf7FDHc2uXs/?ref=app
+ 2
Ketan Lalcheta as you can see that the Playground environment here
has a memory allocation limit somewhere between 1GB (1024MB) and 2GB (2048MB). It's also highly likely there's a timeout in place which most of us already know is relatively short.
https://sololearn.com/compiler-playground/cnyGh8M5SQf9/?ref=app
+ 2
if you're on windows, perhaps this link could be useful
https://learn.microsoft.com/en-us/windows/win32/memory/reserving-and-committing-memory
https://cplusplus.com/forum/windows/67748/