473,386 Members | 1,973 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,386 software developers and data experts.

size?

is there a portable way to write code to get the size that this
code(with data) takes in memory ?
Aug 15 '08 #1
9 1289
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 ---
Aug 15 '08 #2
>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.

Aug 16 '08 #3
Jrdman <ah*********@gmail.comwrites:
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) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 16 '08 #4
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
Aug 16 '08 #5
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 ---
Aug 16 '08 #6
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?

Aug 16 '08 #7
On Aug 16, 8:14*am, santosh <santosh....@gmail.comwrote:
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

Aug 16 '08 #8
On 16 Aug 2008 at 11:50, jr******@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.hand 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...

Aug 16 '08 #9

"Antoninus Twink" <no****@nospam.invalidschreef in bericht
news:sl*******************@nospam.invalid...
On 16 Aug 2008 at 11:50, jr******@gmail.com wrote:
For example, with gcc you can #include <malloc.hand use mallinfo().
dont let my girlfriend read that or she might wanna start programming

Aug 16 '08 #10

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

Similar topics

3
by: Marti | last post by:
Dear everyone, Its my understanding that IE6 now uses a default text-size of "Small" rather than IE5's "Medium". Since I have used relative font-sizes (usually in ems) on all my sites, I am...
25
by: Matthias | last post by:
Hi, I am just reading that book by Scott Meyers. In Item 4 Meyers suggests to always use empty() instead of size() when probing for emptyness of STL containers. His reasoning is that size()...
9
by: Dr John Stockton | last post by:
Assuming default set-ups and considering all reasonable browsers, whatever that may mean, what should an author expect that his readers in general will see (with visual browsers) for a page with...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
27
by: Deephay | last post by:
Greetings all, I have a program that used the realloc() function to change the allocated size of a buffer, the program works with some arguments, but with some other arguments, it will show me...
8
by: redefined.horizons | last post by:
I would like to have an array declaration where the size of the array is dependent on a variable. Something like this: /* Store the desired size of the array in a variable named "array_size". */...
7
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
27
by: 1001 Webs | last post by:
I am trying to make my style sheet as compatible as possible and I'm getting a bit confused here. I've read that the best size for font-size would be 76.1%; due to shortcomings in the way both...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.