+ 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.

4th Feb 2025, 11:09 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
5 odpowiedzi
+ 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
5th Feb 2025, 3:20 PM
Brian
Brian - avatar
+ 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
5th Feb 2025, 6:34 AM
Shardis Wolfe
+ 3
5th Feb 2025, 6:10 PM
Daniel
Daniel - avatar
+ 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
5th Feb 2025, 12:46 AM
BroFar
BroFar - avatar
M
5th Feb 2025, 6:32 AM
Bob_Li
Bob_Li - avatar