473,320 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Tracking the "memory growth" of a process

I have worked out a very simple method for tracking the "memory
growth" of a process at run time. It involves a header file and a
shell script.

Here's the header file:
////////// Header File Begin ///////////////
#ifndef _VIRTMEMINFO_H_
#define _VIRTMEMINFO_H_

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

#define VMEM_BUF_SIZE 200
#define VMEM_ENV_VAR "VMEM_ENV_VAR"
#define CHK_SIZE \
{ \
if(char* envVar=getenv(VMEM_ENV_VAR)) \
{ \
char buf[VMEM_BUF_SIZE]; \
sprintf(buf, "%s %s %d %d %d %d", envVar, \
__FILE__, __LINE__, \
getpid(), getppid(), getpagesize()); \
system(buf); \
} \
}

#endif //_VIRTMEMINFO_H_
////////// Header File End ///////////////
Here's the shell script:
////////// Shell-script Begin ///////////////
#!/bin/ksh
#
# $1: Filename
# $2: Linenumber
# $3: Process id
# $4: Parent process id
# $5: Page Size

echo "File: $1, Line: $2"
echo "Page size is $5"
ps -elf | head -1; ps -elf | grep -w $3 | grep -w $4
echo "\n\n"
////////// Shell-script End ///////////////
By interspersing the above symbolic definition within my code, I am
able to correctly track the memory "growth", but I am not able to see
the memory "shrinkage", as the following coding example shows. Can
someone explain why?

////////// Code-snippet Begin ///////////////
#include "virtmeminfo.h"

main()
{
CHK_SIZE
char *buf = new char[100000];
CHK_SIZE
delete [] buf;
CHK_SIZE
}
////////// Code-snippet End ///////////////

Regards,
Bhat
Jul 22 '05 #1
10 2245

"Generic Usenet Account" <us****@sta.samsung.com> wrote in message
news:90*************************@posting.google.co m...
I have worked out a very simple method for tracking the "memory
growth" of a process at run time. It involves a header file and a
shell script.

Here's the header file:
////////// Header File Begin ///////////////
#ifndef _VIRTMEMINFO_H_
#define _VIRTMEMINFO_H_

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

#define VMEM_BUF_SIZE 200
#define VMEM_ENV_VAR "VMEM_ENV_VAR"
#define CHK_SIZE \
{ \
if(char* envVar=getenv(VMEM_ENV_VAR)) \
{ \
char buf[VMEM_BUF_SIZE]; \
sprintf(buf, "%s %s %d %d %d %d", envVar, \
__FILE__, __LINE__, \
getpid(), getppid(), getpagesize()); \
system(buf); \
} \
}

#endif //_VIRTMEMINFO_H_
////////// Header File End ///////////////
Here's the shell script:
////////// Shell-script Begin ///////////////
#!/bin/ksh
#
# $1: Filename
# $2: Linenumber
# $3: Process id
# $4: Parent process id
# $5: Page Size

echo "File: $1, Line: $2"
echo "Page size is $5"
ps -elf | head -1; ps -elf | grep -w $3 | grep -w $4
echo "\n\n"
////////// Shell-script End ///////////////
By interspersing the above symbolic definition within my code, I am
able to correctly track the memory "growth", but I am not able to see
the memory "shrinkage", as the following coding example shows. Can
someone explain why?

////////// Code-snippet Begin ///////////////
#include "virtmeminfo.h"

main()
{
CHK_SIZE
char *buf = new char[100000];
CHK_SIZE
delete [] buf;
CHK_SIZE
}
////////// Code-snippet End ///////////////

Regards,
Bhat


I don't think that there is any requirement that deleting objects or
otherwise de-allocating memory should cause the operating system to reclaim
that memory immediately. As far as I now, it may do so immediately, or
if/when needed by other processes, or after the program exits. I'm pretty
sure it's operating system dependent (and possibly implementation dependent
as well).

-Howard


Jul 22 '05 #2

"Generic Usenet Account" <us****@sta.samsung.com> wrote in message
news:90*************************@posting.google.co m...
I have worked out a very simple method for tracking the "memory
growth" of a process at run time. It involves a header file and a
shell script.

Here's the header file:
////////// Header File Begin ///////////////
#ifndef _VIRTMEMINFO_H_
#define _VIRTMEMINFO_H_

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

#define VMEM_BUF_SIZE 200
#define VMEM_ENV_VAR "VMEM_ENV_VAR"
#define CHK_SIZE \
{ \
if(char* envVar=getenv(VMEM_ENV_VAR)) \
{ \
char buf[VMEM_BUF_SIZE]; \
sprintf(buf, "%s %s %d %d %d %d", envVar, \
__FILE__, __LINE__, \
getpid(), getppid(), getpagesize()); \
system(buf); \
} \
}

#endif //_VIRTMEMINFO_H_
////////// Header File End ///////////////
Here's the shell script:
////////// Shell-script Begin ///////////////
#!/bin/ksh
#
# $1: Filename
# $2: Linenumber
# $3: Process id
# $4: Parent process id
# $5: Page Size

echo "File: $1, Line: $2"
echo "Page size is $5"
ps -elf | head -1; ps -elf | grep -w $3 | grep -w $4
echo "\n\n"
////////// Shell-script End ///////////////
By interspersing the above symbolic definition within my code, I am
able to correctly track the memory "growth", but I am not able to see
the memory "shrinkage", as the following coding example shows. Can
someone explain why?

////////// Code-snippet Begin ///////////////
#include "virtmeminfo.h"

main()
{
CHK_SIZE
char *buf = new char[100000];
CHK_SIZE
delete [] buf;
CHK_SIZE
}
////////// Code-snippet End ///////////////

Regards,
Bhat


I don't think that there is any requirement that deleting objects or
otherwise de-allocating memory should cause the operating system to reclaim
that memory immediately. As far as I now, it may do so immediately, or
if/when needed by other processes, or after the program exits. I'm pretty
sure it's operating system dependent (and possibly implementation dependent
as well).

-Howard


Jul 22 '05 #3
>> By interspersing the above symbolic definition within my code, I am
able to correctly track the memory "growth", but I am not able to see
the memory "shrinkage", as the following coding example shows. Can
someone explain why?


There is no guarantee that there *IS* any "shrinkage". The process
might not give back any memory to the OS until the program calls
exit(), and even that's not required by ANSI C (but good OS design
argues against massive memory leaks every time you run a program).

Some people argue that such "shrinkage" is *PROHIBITED* by ANSI C.
The argument goes like: if the program gives it back, it might not
be able to get it again, and this violates the ANSI C mandate that
the memory be available for reallocation (which means by the SAME
program, as in ANSI C, there isn't any concept of having more than
one running at the same time).

Gordon L. Burditt
Jul 22 '05 #4
>> By interspersing the above symbolic definition within my code, I am
able to correctly track the memory "growth", but I am not able to see
the memory "shrinkage", as the following coding example shows. Can
someone explain why?


There is no guarantee that there *IS* any "shrinkage". The process
might not give back any memory to the OS until the program calls
exit(), and even that's not required by ANSI C (but good OS design
argues against massive memory leaks every time you run a program).

Some people argue that such "shrinkage" is *PROHIBITED* by ANSI C.
The argument goes like: if the program gives it back, it might not
be able to get it again, and this violates the ANSI C mandate that
the memory be available for reallocation (which means by the SAME
program, as in ANSI C, there isn't any concept of having more than
one running at the same time).

Gordon L. Burditt
Jul 22 '05 #5
Generic Usenet Account wrote:
I have worked out a very simple method for tracking the "memory
growth" of a process at run time. It involves a header file and a
shell script.


Please remove comp.lang.c from the crossposting list for C++ code.
Please remove comp.lang.c from the crossposting list for unix-specific code.

Follow-ups so set.
I can see why you hide behind a pseudonym.
Jul 22 '05 #6
Generic Usenet Account wrote:
I have worked out a very simple method for tracking the "memory
growth" of a process at run time. It involves a header file and a
shell script.


Please remove comp.lang.c from the crossposting list for C++ code.
Please remove comp.lang.c from the crossposting list for unix-specific code.

Follow-ups so set.
I can see why you hide behind a pseudonym.
Jul 22 '05 #7
Howard wrote to (among others) comp.lang.c:

[Off-topic answer to off-topic question]
Please remove comp.lang.c from the crossposting list for C++ code.
Please remove comp.lang.c from the crossposting list for unix-specific code.

Follow-ups so set.

Jul 22 '05 #8
Howard wrote to (among others) comp.lang.c:

[Off-topic answer to off-topic question]
Please remove comp.lang.c from the crossposting list for C++ code.
Please remove comp.lang.c from the crossposting list for unix-specific code.

Follow-ups so set.

Jul 22 '05 #9
Generic Usenet Account wrote:
////////// Header File Begin ///////////////
#ifndef _VIRTMEMINFO_H_
#define _VIRTMEMINFO_H_
Identifiers beginning with an underscore followed by an uppercase letter
(or another underscore) are reserved for the implementation for any use,
and C & C++ programs are forbidden to use them. Never use an identifier
with a leading underscore (or a sequence of two underscores anywhere in
the name) unless you are sure you know what you are doing.

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
Code using system-specific extensions is not welcome on comp.lang.c or
comp.lang.c++.

main()


You need to specify the return type (which must be 'int') here. There is
no longer an "implicit int" rule in either C or C++. C++ has been
without this rule for something like 10 years. C for almost 5.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #10
Generic Usenet Account wrote:
////////// Header File Begin ///////////////
#ifndef _VIRTMEMINFO_H_
#define _VIRTMEMINFO_H_
Identifiers beginning with an underscore followed by an uppercase letter
(or another underscore) are reserved for the implementation for any use,
and C & C++ programs are forbidden to use them. Never use an identifier
with a leading underscore (or a sequence of two underscores anywhere in
the name) unless you are sure you know what you are doing.

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
Code using system-specific extensions is not welcome on comp.lang.c or
comp.lang.c++.

main()


You need to specify the return type (which must be 'int') here. There is
no longer an "implicit int" rule in either C or C++. C++ has been
without this rule for something like 10 years. C for almost 5.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #11

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

Similar topics

0
by: John Bonds | last post by:
I have designed a multi-threaded application that manipulates images (CCITT Group 4 TIFF Images). I'm getting some strange behavior and I'm wondering if anyone else is seeing the same thing. I run...
5
by: Scott Brady Drummonds | last post by:
Hi, everyone, A coworker and I have been pondering a memory allocation problem that we're having with a very large process. Our joint research has led us to the conclusion that we may have to...
10
by: Generic Usenet Account | last post by:
I have worked out a very simple method for tracking the "memory growth" of a process at run time. It involves a header file and a shell script. Here's the header file: ////////// Header File...
5
by: Jarek | last post by:
Hi all! I'm optimizing my C++ multi-threaded application (linux). My application consumes huge amout of memory from unknown reason. There are no memory leaks, or other allocation bugs,...
4
by: Rachel McConnell | last post by:
Hello, I have a Java web application using Hibernate to connect to a PostgreSQL backend. I am seeing the below stack trace during processing of a set of data consisting of around 1000 objects;...
1
by: Joe Peterson | last post by:
I've been doing a lot of searching on the topic of one of Python's more disturbing issues (at least to me): the fact that if a __del__ finalizer is defined and a cyclic (circular) reference is...
1
by: =?Utf-8?B?QXJuZSBCZXJ1bGRzZW4=?= | last post by:
I'm relatively new to vb.net (2005) and I continually experience an out of memory exception during the development process...and this is becoming a big pain!! I have 2gigs of memory and this...
1
by: Erik Johnson | last post by:
Sort of two questions here: The first is about the internal view: are there Python introspection functions that can be called such that a running script can keep tabs on how much memory is being...
0
by: Steve Holden | last post by:
Hank @ITGroup wrote: It doesn't really make that much sense to watch memory usage as you have been doing. Your first test case appears to trigger a specific pathology, where the memory allocator...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.