[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Jrdman

8/15/2008 11:28:00 PM

is there a portable way to write code to get the size that this
code(with data) takes in memory ?
9 Answers

Joe Wright

8/15/2008 11:54:00 PM

0

Jrdman wrote:
> is there a portable way to write code to get the size that this
> code(with data) takes in memory ?

What code? What data? Your mind is terribly hard to read from here.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---

gordonb.a0waq

8/16/2008 12:03:00 AM

0

>is there a portable way to write code to get the size that this
>code(with data) takes in memory ?

No.

The amount of memory that the code takes may vary at runtime, either
due to direct calls to malloc() or library use of it (For example,
it's possible the library will not allocate a buffer for stdout
until the program outputs something. Or the library allocates
buffers for every file open simultaneously, which can vary with
user input). The program's memory use may vary heavily with such
things as the quantity of input.

The amount of memory taken by shared libraries (which may be used
whether or not the program or even the compiler command line
specifically mentions them) will vary with the version of the library
and the platform.

In typical implementations the amount of memory taken by argv[] and
the argument strings will vary depending on the command that invoked
it. A similar issue exists with environment variables, which are
typically (but the standard doesn't require it) stored somewhere
in memory.

The amount of memory taken by automatic variables will vary with
the execution path, especially in recursive programs where the
recursion depth depends on user input.

Some linkers allow options which may affect the memory size of the
program, such as the size of a fixed stack. Other systems grow the
stack as needed.

Flash Gordon

8/16/2008 12:22:00 AM

0

Joe Wright wrote, On 16/08/08 00:53:
> Jrdman wrote:
>> is there a portable way to write code to get the size that this
>> code(with data) takes in memory ?
>
> What code? What data? Your mind is terribly hard to read from here.

It doesn't matter. There is to portable way to find the size of *any*
code, so there is no portable way to find the size of whatever code the
OP is talking about.
--
Flash Gordon

Keith Thompson

8/16/2008 12:37:00 AM

0

Jrdman <ahmed.bou23@gmail.com> writes:
> is there a portable way to write code to get the size that this
> code(with data) takes in memory ?

No.

There may well be non-portable ways to do it. Try a newsgroup that
deals with whatever system you're using. You may need to be more
specific. Do you mean an entire program? A single function? A
translation unit (roughly a source file)? Which of the three storage
durations are included in "data"?

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Joe Wright

8/16/2008 1:27:00 AM

0

Flash Gordon wrote:
> Joe Wright wrote, On 16/08/08 00:53:
>> Jrdman wrote:
>>> is there a portable way to write code to get the size that this
>>> code(with data) takes in memory ?
>>
>> What code? What data? Your mind is terribly hard to read from here.
>
> It doesn't matter. There is to portable way to find the size of *any*
> code, so there is no portable way to find the size of whatever code the
> OP is talking about.

You're right of course. I was trying to find out what jrdman really
wanted to do.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---

santosh

8/16/2008 8:14:00 AM

0

Jrdman wrote:

> is there a portable way to write code to get the size that this
> code(with data) takes in memory ?

It's possible to estimate the size your data objects may take (I say
only estimate because of padding and other overheads), but it's much
more difficult to say how much memory your code takes. In any case both
are not possible with Standard C. In fact this problem is better solved
with external tools (like gdb, Valgrind etc.) than from within the
program itself. Why do you need the size of your code and data at
runtime anyway?

jrdacc.i

8/16/2008 11:50:00 AM

0

On Aug 16, 8:14 am, santosh <santosh....@gmail.com> wrote:
> Jrdman wrote:
> > is there a portable way to write code to get the size that  this
> > code(with data) takes in memory ?
>
> It's possible to estimate the size your data objects may take (I say
> only estimate because of padding and other overheads), but it's much
> more difficult to say how much memory your code takes. In any case both
> are not possible with Standard C. In fact this problem is better solved
> with external tools (like gdb, Valgrind etc.) than from within the
> program itself. Why do you need the size of your code and data at
> runtime anyway?

i want to get the amount of memory that my program takes in the start,
and as long as the program is running,when this amount get changed the
program update the output value that represent the ammount of memory
and echo it

John B. Matthews

8/16/2008 11:57:00 AM

0

On 16 Aug 2008 at 11:50, jrdacc.i@gmail.com wrote:
> i want to get the amount of memory that my program takes in the start,
> and as long as the program is running,when this amount get changed the
> program update the output value that represent the ammount of memory
> and echo it

If you're interested in the amount of memory that's been dynamically
allocated so far, then your C implementation can probably tell you. For
example, with gcc you can #include <malloc.h> and use mallinfo().

For the total memory usage of your process, you may be able to find that
out from the kernel: for example, on Linux you could investigate
/proc/<pid>/status. How useful the information you'll get is is another
question though...

Serve Lau

8/16/2008 3:39:00 PM

0


"Antoninus Twink" <nospam@nospam.invalid> schreef in bericht
news:slrngadg49.4mp.nospam@nospam.invalid...
> On 16 Aug 2008 at 11:50, jrdacc.i@gmail.com wrote:
> For example, with gcc you can #include <malloc.h> and use mallinfo().

dont let my girlfriend read that or she might wanna start programming