473,799 Members | 3,098 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to find available memory in linux box

I have a problem that is used to test memory leak as follows, however,
after each run of the program, if I am using the command "free" on the
linux box, I did not see any difference about the usable memory. My
questions are:
1) How to find out exact free memory that my program can use?
2) Use which command to do this (top, or free)
3) why it does not show memory leak in my case (I am using the linux
command free)

----------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <new>
#include <stdlib.h>
using namespace std;
int main(){
int *p= new int[100000000];
if ( p == NULL ) cout << "Failed to allocate memory" << endl;
else {
p[0] = 1;
p[1] = 2;
p[2] = 3;
cout << "p[0] = " << p[0] << ", p[1] = " << p[1] << ", p[2]
= " << p[2] << endl;
}
}

--------------------------------------------------------------------------------------------------------------------------------------------

$ a.out
p[0] = 1, p[1] = 2, p[2] = 3
$ free
total used free shared buffers
cached
Mem: 3907304 3884812 22492 0 281760
3123052
-/+ buffers/cache: 480000 3427304
Swap: 4145288 16084 4129204
$ a.out
p[0] = 1, p[1] = 2, p[2] = 3
$ free
total used free shared buffers
cached
Mem: 3907304 3884812 22492 0 281760
3123052
-/+ buffers/cache: 480000 3427304
Swap: 4145288 16084 4129204

Dec 6 '06 #1
7 5111
david wolf wrote:
I have a problem that is used to test memory leak as follows, however,
after each run of the program, if I am using the command "free" on the
linux box, I did not see any difference about the usable memory. My
questions are:
1) How to find out exact free memory that my program can use?
2) Use which command to do this (top, or free)
3) why it does not show memory leak in my case (I am using the linux
command free)
All good questions. Wrong newsgroup, though. Try 'comp.os.linux. *'
hierarchy. Good luck!

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 6 '06 #2


On Dec 7, 5:46 am, "david wolf" <yih...@gmail.c omwrote:
I have a problem that is used to test memory leak as follows, however,
after each run of the program, if I am using the command "free" on the
linux box, I did not see any difference about the usable memory. My
questions are:
1) How to find out exact free memory that my program can use?
2) Use which command to do this (top, or free)
3) why it does not show memory leak in my case (I am using the linux
command free)

---------------------------------------------------------------------------*-------------------------------------
#include <iostream>
#include <new>
#include <stdlib.h>
using namespace std;

int main(){
int *p= new int[100000000];
if ( p == NULL ) cout << "Failed to allocate memory" << endl;
else {
p[0] = 1;
p[1] = 2;
p[2] = 3;
cout << "p[0] = " << p[0] << ", p[1] = " << p[1] << ", p[2]
= " << p[2] << endl;
}

}---------------------------------------------------------------------------*-----------------------------------------------------------------

$ a.out
p[0] = 1, p[1] = 2, p[2] = 3
$ free
total used free shared buffers
cached
Mem: 3907304 3884812 22492 0 281760
3123052
-/+ buffers/cache: 480000 3427304
Swap: 4145288 16084 4129204
$ a.out
p[0] = 1, p[1] = 2, p[2] = 3
$ free
total used free shared buffers
cached
Mem: 3907304 3884812 22492 0 281760
3123052
-/+ buffers/cache: 480000 3427304
Swap: 4145288 16084 4129204
As your program 'a.out' finished the memory have been 'free', the
memory record is same. Some os implements copy-on-wirte tech, so the
virtual address (not memory) you alloc may not exist in physical
memory, until you write something to it. Try check /proc file system
instead of 'free' command. At last, It's not a good idear to check
memory leak like this, which program's (process's) memory leak you want
see ?

Dec 7 '06 #3
Thanks Xeranic.

But how to check /proc file system?

Xeranic wrote:
On Dec 7, 5:46 am, "david wolf" <yih...@gmail.c omwrote:
I have a problem that is used to test memory leak as follows, however,
after each run of the program, if I am using the command "free" on the
linux box, I did not see any difference about the usable memory. My
questions are:
1) How to find out exact free memory that my program can use?
2) Use which command to do this (top, or free)
3) why it does not show memory leak in my case (I am using the linux
command free)

---------------------------------------------------------------------------*-------------------------------------
#include <iostream>
#include <new>
#include <stdlib.h>
using namespace std;

int main(){
int *p= new int[100000000];
if ( p == NULL ) cout << "Failed to allocate memory" << endl;
else {
p[0] = 1;
p[1] = 2;
p[2] = 3;
cout << "p[0] = " << p[0] << ", p[1] = " << p[1] << ", p[2]
= " << p[2] << endl;
}

}---------------------------------------------------------------------------*-----------------------------------------------------------------

$ a.out
p[0] = 1, p[1] = 2, p[2] = 3
$ free
total used free shared buffers
cached
Mem: 3907304 3884812 22492 0 281760
3123052
-/+ buffers/cache: 480000 3427304
Swap: 4145288 16084 4129204
$ a.out
p[0] = 1, p[1] = 2, p[2] = 3
$ free
total used free shared buffers
cached
Mem: 3907304 3884812 22492 0 281760
3123052
-/+ buffers/cache: 480000 3427304
Swap: 4145288 16084 4129204

As your program 'a.out' finished the memory have been 'free', the
memory record is same. Some os implements copy-on-wirte tech, so the
virtual address (not memory) you alloc may not exist in physical
memory, until you write something to it. Try check /proc file system
instead of 'free' command. At last, It's not a good idear to check
memory leak like this, which program's (process's) memory leak you want
see ?
Dec 7 '06 #4

david wolf wrote:
I have a problem that is used to test memory leak as follows, however,
after each run of the program, if I am using the command "free" on the
linux box, I did not see any difference about the usable memory.
3) why it does not show memory leak in my case (I am using the linux
command free)
Because when your program terminates the OS reclaims the resources it
reserved.

Dec 7 '06 #5
TvN
Hi David,
I have a problem that is used to test memory leak as follows, however,
after each run of the program, if I am using the command "free" on the
linux box, I did not see any difference about the usable memory. My
questions are:
1) How to find out exact free memory that my program can use?
It depends on: you limits (ulimit -a) , available memory, etc
3) why it does not show memory leak in my case (I am using the linux
command free)
Use valgrind for this.

Best regards,
Volodymyr!

Dec 7 '06 #6
david wolf <yi****@gmail.c omwrote:
I have a problem that is used to test memory leak as follows, however,
after each run of the program, if I am using the command "free" on the
linux box, I did not see any difference about the usable memory. My
questions are:
1) How to find out exact free memory that my program can use?
2) Use which command to do this (top, or free)
3) why it does not show memory leak in my case (I am using the linux
command free)

----------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <new>
#include <stdlib.h>
using namespace std;
int main(){
int *p= new int[100000000];
if ( p == NULL ) cout << "Failed to allocate memory" << endl;
This doesn't answer your question, but in case allocation fails, new
will throw an exception. If you want it to return NULL, you have to use
new(std::nothro w) or something like that.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Dec 7 '06 #7
Yes, Valgrind is best.

On Dec 8, 1:43 am, "david wolf" <yih...@gmail.c omwrote:
Thanks Xeranic.

But how to check /proc file system?

Xeranic wrote:
On Dec 7, 5:46 am, "david wolf" <yih...@gmail.c omwrote:
I have a problem that is used to test memory leak as follows, however,
after each run of the program, if I am using the command "free" on the
linux box, I did not see any difference about the usable memory. My
questions are:
1) How to find out exact free memory that my program can use?
2) Use which command to do this (top, or free)
3) why it does not show memory leak in my case (I am using the linux
command free)
---------------------------------------------------------------------------*-------------------------------------
#include <iostream>
#include <new>
#include <stdlib.h>
using namespace std;
int main(){
int *p= new int[100000000];
if ( p == NULL ) cout << "Failed to allocate memory" << endl;
else {
p[0] = 1;
p[1] = 2;
p[2] = 3;
cout << "p[0] = " << p[0] << ", p[1] = " << p[1] << ", p[2]
= " << p[2] << endl;
}
}---------------------------------------------------------------------------*-----------------------------------------------------------------
$ a.out
p[0] = 1, p[1] = 2, p[2] = 3
$ free
total used free shared buffers
cached
Mem: 3907304 3884812 22492 0 281760
3123052
-/+ buffers/cache: 480000 3427304
Swap: 4145288 16084 4129204
$ a.out
p[0] = 1, p[1] = 2, p[2] = 3
$ free
total used free shared buffers
cached
Mem: 3907304 3884812 22492 0 281760
3123052
-/+ buffers/cache: 480000 3427304
Swap: 4145288 16084 4129204
As your program 'a.out' finished the memory have been 'free', the
memory record is same. Some os implements copy-on-wirte tech, so the
virtual address (not memory) you alloc may not exist in physical
memory, until you write something to it. Try check /proc file system
instead of 'free' command. At last, It's not a good idear to check
memory leak like this, which program's (process's) memory leak you want
see ?
Dec 14 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5888
by: bouchia.nazha | last post by:
Hello I have encountered a problem using tomcat, linux and ssl. My problem seem to be a JVM memory deallocation problem on Linux. This is my configuration: OS: Redhat7.2 Tomcat: 4.0 Jdk: 1.3.1_07
3
2596
by: Ian | last post by:
Hi all, I have a problem. I have an application which needs to work with a lot of data, but not all at the same time. It is arranged as a set of objects, each with lots of data that is created when the object is instantiated. I'd ideally like to keep as many objects as possible in memory, but I can get rid of any object the program isn't currently using. Is there any way I can access the amount of memory python is using? I can
5
2344
by: Darren Dale | last post by:
I am doing linear algebra with large numarray. It is very efficient, but I have a small problem due to the size of my data. The dot product of a 10,000x3 double array with a 3x6,250,000 double array will consume 500GB of memory. I need to break the operations up into managable chunks, so I dont consume all the available memory and get a segmentation fault. Its not a problem with numpy, I just need to intelligently slice up one of my...
3
2503
by: Dean Arpajian | last post by:
Looking to find info/ libs on creating (small) video files. Basically what I'm looking for is a tutorial for constructing a short video... (nothing nasty: output from a transmission line simulation). I've been searching for a while now, and all I get is info for creation inside someone else's app. Rather useless for me. The sim needs to be web accessible. So I was thinking mpeg, quicktime, wmv, avi, etc.
5
45735
by: Jeong-Gun Lee | last post by:
I'm writing a code of writing a value to a specific memory address. ================================================================= #include <stdio.h> int main() { long air; long *air_address;
1
6178
by: aaron | last post by:
Output of "top" prior to initiation of mysql: load averages: 0.60, 0.97, 1.05 19:03:45 44 processes: 43 sleeping, 1 on cpu CPU states: 97.1% idle, 0.0% user, 0.8% kernel, 2.1% iowait, 0.0% swap Memory: 4096M real, 3646M free, 42M swap in use, 3494M swap free PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND
0
1953
by: mandarkraftware | last post by:
Hi All, Let me present you with list of consultants currently available. Name / Job Title Summary Ramchandran/Java · 7+ years experience in the field of Software Development. · Expertise in full Software Development Life Cycle (SDLC)
1
1808
by: Sachin | last post by:
Hi All, Let me present you with list of consultants currently available. Name / Job Title Summary Ramchandran/Java · 7+ years experience in the field of Software Development. · Expertise in full Software Development Life Cycle (SDLC)
5
3714
by: pp | last post by:
hi, on window we can GlobalMemoryStatusEx() to get the memory status on the system do we have any equivalent function on Unix/linux? can we use BOOST library to memory information on the unix? please help me.
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10482
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10225
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.