how to get correct physical memory and virtual memory - visual-c++

I use this windows API,
http://msdn.microsoft.com/en-us/library/aa366589(v=vs.85).aspx
GlobalMemoryStatusEx to get memory information
my computer total physcial memory is 4096MB ,why the program shows 3.XG
My computer's virtual memory is 3063MB ,but i use program which show 2047MB
my develop enviroment is visual studio 2008
how to modify this problem
thanks

Aren't other programs using your system as well? I suspect the memory you're "missing" is due to the OS itself and whatever other programs you're running. See if having a bunch of other applications open changes the virtual memory size that your program is able to see.

Assuming you are running a 32bit version of windows, then this is a limit of windows itself. See this Microsoft page for the details. By default you will only be able to access 2GB of RAM in a single process. There is a compiler switch in visual studio which will give you access to 3GB. This is the /LARGEADDRESSAWARE switch. Beyond that you just need to upgrade to a 64bit operating system.
By the way, the basic reason why you don't automatically get 4GB of address space is because part of it is reserved for the operating system. Those system calls and references to operating system resources have to live somewhere.

Related

C++ memory writing without API

How do I enable my program to read/write another process's memory in C++ without using anything like Windows.h?
I'm running on visual studio in windows 10.
Thanks.
The simple answer is that you can't. Process memory management is inherently OS specific so you need to work with the OS.

Windows Program Memory Vs Linux Program Memory

Linux creates virtual memory pages for every program to use, and the OS handles mapping the virtual addresses to genuine hardware addresses, correct?
But how does Windows do this? Do Windows programs actually have memory that translates to real hardware addresses? I'm also aware that windows can use hard disk memory when RAM is over used, and this process is again called virtual memory, but I believe this is an entirely different concept?
Windows and Linux (at least on Intel 32/64 bit systems) both implement virtual memory using the same mechanism: hardware supported page tables. The OS and the hardware cooperate together to do the address mapping.
The entire concept of separating the logical addresses a program uses from the physical addresses is what is called virtual memory. The use of the hard disk as a backing store is an implementation of virtual memory that uses a swap file to increase the amount of virtual memory to an amount greater than the physical memory installed in the system.
Virtual memory is a pretty deep and wide subject. Maybe start with this Wiki article an Memory Management and then hit the googles for a deeper understanding.

Restricting available memory for testing on linux

The machine on which I develop has more memory than the one on which the code will eventually run. I dont have access tothe machine on which it will actually run. This is a 64 bit application and I intend to use the address space but cap physical allocation. I dont want to lock down virtual memory, only physical memory. Is there a way to set limits on a linux machine such that it mimics a system with low RAM. I think ulimit does not differentiate between reserved address space vs actual allocation. If there is a way to do it without rebooting with different kernel parameters or, pulling out extra RAM that would be great. May be some /proc tricks.
See https://unix.stackexchange.com/questions/44985/limit-memory-usage-for-a-single-linux-process which suggests using "timeout" from here: https://github.com/pshved/timeout .
If You can change boot command line of the kernel and want to restrict available memory use
mem=
boot parameter.
For more information check:
https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html

Linux low profile image to run Virtual Box

I want a Linux image which can use low resources (RAM & CPU) and is capable of running:
1. Virtual Box
2. A browser
Actually my system does not have enough memory to run Windows Server in Virtual Box so I need that solution.
I suggest you to configure the kernel as you wish. By default, so many services/resources come with Linux. Which eats most of memory and CPU time.
For compiling Linux kernel pls refer http://www.cyberciti.biz/tips/compiling-linux-kernel-26.html
If you wish to reduce your file system size then plz refere http://tldp.org/HOWTO/Bootdisk-HOWTO/buildroot.html
I think Suse Studio is fine when need to customize the Linux image.

kvm balloon driver results in different total-memory then requested

I have ubuntu and installed on it several qemu-kvm guests, running also ubuntu.
I'm using libvirt to change the guests' memory allocation. But always encounter a constant difference between the requested memory allocation and the actual memory allocation I query from the Total field in the top command inside the guests.
The difference is the same in all the guests, and consistent.
In one machine I installed it is 134MB (allocated is less then requested), In another one it is 348MB.
I can live with it, I just don't know the reason. Does someone encounter this kind of problem? Maybe solved it?
Thanks
This constant difference is likely the space reserved by the kernel. Note that this amount of space will increase (at least in Linux) as you have more physical memory available in the system. The change you're seeing is probably due to kvm giving that particular guest more or less memory to work with than it was before.
If you're interested, here is a quick article on memory ballooning, as implemented by VMWare ESX Server.

Resources