Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Memory consumption

Reply
Thread Tools

Memory consumption

 
 
MN
Guest
Posts: n/a
 
      03-12-2009
Hello,
Is there any c function or command under linux that reports statistics
for a given program, that uses memory allocation? specially, what I
want is to know memory used when running program.
 
Reply With Quote
 
 
 
 
Edwin van den Oetelaar
Guest
Posts: n/a
 
      03-12-2009
MN wrote:
> Hello,
> Is there any c function or command under linux that reports statistics
> for a given program, that uses memory allocation? specially, what I
> want is to know memory used when running program.


you mean 'top' or 'htop' ?
 
Reply With Quote
 
 
 
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      03-12-2009
MN <(E-Mail Removed)> wrote:
> Is there any c function or command under linux that reports statistics
> for a given program, that uses memory allocation? specially, what I
> want is to know memory used when running program.


There's no standard C function for this. You will have to
resort to system specific functions and thus better ask
in e.g. comp.unix.pogrammer. But note that the same ques-
tion was asked there a few days ago (March 5th, by Rui
Maciel, "Measure program memory usage?"). And the summary
of the answers is that on modern systems, especially those
that use virtual memory, there is no simple answer - do you
mean virtual memory or physical memory? What about memory
you malloc()ed but did not yet use and thus may not be map-
ped physically into the address space of your process? Do
you count in the memory used for shared libraries that are
also used by other processes at the same time etc.?

Regards, Jens
--
\ Jens Thoms Toerring ___ http://www.velocityreviews.com/forums/(E-Mail Removed)
\__________________________ http://toerring.de
 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      03-12-2009
MN wrote:
> Hello,
> Is there any c function or command under linux that reports statistics
> for a given program, that uses memory allocation? specially, what I
> want is to know memory used when running program.


You system/implementation may have the non-standard mallinfo(). The GNU
C-Library for example provides it as does IBM, SUN, HP, SGI.
Check your documentation.

Bye, Jojo

 
Reply With Quote
 
Antoninus Twink
Guest
Posts: n/a
 
      03-12-2009
On 12 Mar 2009 at 18:40, Joachim Schmitz wrote:
> MN wrote:
>> Is there any c function or command under linux that reports statistics
>> for a given program, that uses memory allocation? specially, what I
>> want is to know memory used when running program.

>
> You system/implementation may have the non-standard mallinfo().


You may also be able to find out the total memory usage of your process
from the kernel: for example, on Linux you could investigate
/proc/<pid>/status.

Whatever method you use, how useful the information you'll get will be
is another question...

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      03-13-2009
Joachim Schmitz wrote:
> MN wrote:
>
>> Is there any c function or command under linux that reports
>> statistics for a given program, that uses memory allocation?
>> specially, what I want is to know memory used when running
>> program.

>
> You system/implementation may have the non-standard mallinfo().
> The GNU C-Library for example provides it as does IBM, SUN, HP,
> SGI. Check your documentation.


My implementation of malloc for DJGPP, nmalloc, also includes a
malldbg module that provides that same facility (and others).
nmalloc is quite general, and should mount on any system that
supplies sbrk to access memory. It also assumes at least CHAR_BIT
== 8 and 32 bit integers. See:

<http://cbfalconer.home.att.net/download/nmalloc.zip>

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      03-13-2009
Han from China wrote:
> CBFalconer wrote:
>> nmalloc is quite general, and should mount on any system that
>> supplies sbrk to access memory.

>
> I don't see sbrk() in my copy of the C standard.


That's most probably why he wrote: "on any system that supplies sbrk"

Bye, Jojo
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      03-13-2009
In article <(E-Mail Removed) t>,
Han from China <(E-Mail Removed)> wrote:
>Joachim Schmitz wrote:
>> Han from China wrote:
>>> I don't see sbrk() in my copy of the C standard.

>>
>> That's most probably why he wrote: "on any system that supplies sbrk"

>
>Right. So if people start providing Web links to software that uses,
>say, POSIX threads, with the comment "should work on any system that
>supplies POSIX threads", Falconer won't complain, right?


Exactly. In the dogma of this group, any mention of things deemed "off
topic" by the ruling clan, is met with an immediate rubuke (or several).

Except, of course, if it is done by one of the ruling clan.

>You don't need to answer that. The answer is already available in
>the archives, where he's seen bitching at people who post links to
>code that uses non-ISO features. He's a hypocritical Net Nannying
>piece of ****.


And you're being kind.

 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      03-13-2009
On 2009-03-13, Joachim Schmitz <(E-Mail Removed)> wrote:
> Han from China wrote:
>> CBFalconer wrote:
>>> nmalloc is quite general, and should mount on any system that
>>> supplies sbrk to access memory.

>>
>> I don't see sbrk() in my copy of the C standard.

>
> That's most probably why he wrote: "on any system that supplies sbrk"


If you muck around with sbrk, you may break your malloc implementation, so your
malloc should replace it completely.

The malloc implementation in glibc is defensively coded against this. It will
notice that someone has moved the break location behind its back. After that,
it will continue to work, but it will not be able to return memory to the
operating system when the program calls free (at least not from the principal
heap). This is a lucky case. Another malloc implementation might simply not
bother to check whether sbrk has moved. Once you use brk or sbrk, you can't
use malloc. Your allocator should provide a complete replacement which is used
by everything in the address space.

Any halfway sane do-it-yourself allocator targetting Unix uses anonymous mmap
for grabbing memory.

Now the above are just my hacker intuitions. But what does the Single Unix
Specification actually say? What do you know. It denotes these functions as
legacy interfaces. As in, obsolete junk. Do not use. And---aha!---there is
this text:

The behaviour of brk() and sbrk() is unspecified if an application
also uses any other memory functions (such as malloc(), mmap(),
free()). Other functions may use these other memory functions silently.

There you go.
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      03-14-2009
Kaz Kylheku wrote:
> Joachim Schmitz <(E-Mail Removed)> wrote:
>> Han from China wrote:
>>> CBFalconer wrote:
>>>
>>>> nmalloc is quite general, and should mount on any system that
>>>> supplies sbrk to access memory.
>>>
>>> I don't see sbrk() in my copy of the C standard.

>>
>> That's most probably why he wrote: "on any system that supplies
>> sbrk"

>
> If you muck around with sbrk, you may break your malloc
> implementation, so your malloc should replace it completely.
>
> The malloc implementation in glibc is defensively coded against
> this. ...


You obviously have not read the source of nmalloc.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Low power consumption board with memory Duccio VHDL 0 02-25-2006 10:12 PM
Per-session memory consumption in ASP.NET worker process Jim Campbell ASP .Net 1 02-12-2004 05:48 PM
aspnet_wp.exe was recycled because memory consumption exceeded the tony_wang ASP .Net 1 11-21-2003 07:28 AM
Urgent! GDI+ Memory consumption Ervin ASP .Net 0 09-15-2003 07:58 PM
aspnet_wp.exe memory consumption Kiran Kumar ASP .Net 1 07-15-2003 12:08 PM



Advertisments