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

with respect to the memory

thanks a lot Lew Pitcher.

one more doubt i have it is: we are declaring a structure and the
memory for that structure will be allocated only when i creat some
objects to that one right?
so where the momory will be allocated for structure signature and for
objects?

i will be thankfull if you or someone clarify this one too

thanks

May 23 '07 #1
5 1304
In article <11*********************@w5g2000hsg.googlegroups.c om>,
<je****@gmail.comwrote:
>one more doubt i have it is: we are declaring a structure and the
memory for that structure will be allocated only when i creat some
objects to that one right?
so where the momory will be allocated for structure signature and for
objects?
That's going to depend upon the compiler.

No space needs to be allocated for the "structure signature"
(whatever that is exactly): the offsets of structure members
are constants, so all of the code to access them can be compiled
right into the executable.

Objects are allocated in whatever kind of storage you declared
for them -- static, auto, dynamic. The exact (or even relative)
location of these types of memory in an executable is compiler dependant.
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
May 23 '07 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

je****@gmail.com wrote:
thanks a lot Lew Pitcher.
You're welcome.
one more doubt i have it is: we are declaring a structure and the
memory for that structure will be allocated only when i creat some
objects to that one right?
You have the concept correct.
so where the momory will be allocated for structure signature and for
objects?
You have asked two questions here. Lets separate them so that the answers will
be clear.

Q1: Where will the memory be allocated for the structure definition?
Q2: Where will the memory be allocated for a specific declaration of an object
of a particular structure?

Question 1 is fairly simple: there is no memory allocated to a structure
definition. Period.

Question 2 is a little more complicated, and can be answered in several ways.
The pedants here might take exception to my answer, and they will provide
better, more accurate responses.

a) It depends. More specifically, it depends on whether you declare the object
as a static, an auto, or an extern, and it depends on whether or not you
provide an initializer for the contents of the object.

b) C makes no distinction between BSS and DATA. In fact, those terms have
nothing to do with C as a language. They /do/ have to do with the
implementation of your local C compiler on your local system, though. The best
we can tell you is that if you declare the object as 'static', the language
guarantees that the object will reside in the space set aside for 'static'
objects, and if you declare the object as 'auto', then the object will reside
in the space set aside for 'auto' objects. These two spaces /may/ be the same
physical space, or may be different physical spaces - that's beyond the
definition of the language.

i will be thankfull if you or someone clarify this one too

HTH
- --
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
- ---------- Slackware - Because I know what I'm doing. ------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Armoured with GnuPG

iD8DBQFGVGD8agVFX4UWr64RAvI1AJ0VOhE1JKZqn7IvR1QdTi DkR9nGxgCfaqkp
qhejG0h7hHuEs8USxsC5h7I=
=deLg
-----END PGP SIGNATURE-----
May 23 '07 #3
Lew Pitcher <lp******@teksavvy.comwrites:
[...]
b) C makes no distinction between BSS and DATA. In fact, those terms
have nothing to do with C as a language. They /do/ have to do with
the implementation of your local C compiler on your local system,
though. The best we can tell you is that if you declare the object
as 'static', the language guarantees that the object will reside in
the space set aside for 'static' objects, and if you declare the
object as 'auto', then the object will reside in the space set aside
for 'auto' objects. These two spaces /may/ be the same physical
space, or may be different physical spaces - that's beyond the
definition of the language.
I'm going to quibble about the phrase "the space set aside". There
needn't be any space specifically set aside for either static or auto
objects.

All we can really say is that static objects exist during the entire
execution of the program, and auto objects exist only during the
execution of the enclosing compound statement.

(A compiler may vary this as long as any such variation has no visible
effect; for example, a declared object might not be stored anywhere if
the program never access it, or an auto object may be stored as if it
were static if the compiler can prove that the enclosing function is
never called recursively. The latter, as far as I know, is not a
likely thing for a compiler to do, since it doesn't really save time
or space.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 23 '07 #4
je****@gmail.com wrote:
>
one more doubt i have it is: we are declaring a structure and the
memory for that structure will be allocated only when i creat some
objects to that one right? so where the momory will be allocated
for structure signature and for objects?
See the following sig. Without proper quoting and linking to
previous messages this is totally meaningless. At any rate, memory
disposition etc. is not a C language matter, and is totally
off-topic here.

--
If you want to post a followup via groups.google.com, ensure
you quote enough for the article to make sense. Google is only
an interface to Usenet; it's not Usenet itself. Don't assume
your readers can, or ever will, see any previous articles.
More details at: <http://cfaj.freeshell.org/google/>

--
Posted via a free Usenet account from http://www.teranews.com

May 24 '07 #5
Keith Thompson wrote:
(A compiler may vary this as long as any such variation has no visible
effect; for example, a declared object might not be stored anywhere if
the program never access it, or an auto object may be stored as if it
were static if the compiler can prove that the enclosing function is
never called recursively. The latter, as far as I know, is not a
likely thing for a compiler to do, since it doesn't really save time
or space.)
Actually, I have worked with a compiler which did just that.
I must admit that the compiler was not fully conforming (because
functions could not be used recursively without some extra decoration),
but the compiler would give all objects with automatic storage duration
a fixed address.
To conserve memory, would two objects that could never be alive at the
same time be allocated to overlapping memory areas.

This was a compiler for a small embedded platform (addressable memory
was 64kB)

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
May 29 '07 #6

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

Similar topics

15
by: Nick Coghlan | last post by:
Thought some folks here might find this one interesting. No great revelations, just a fairly sensible piece on writing readable code :) The whole article:...
10
by: AlexS | last post by:
Hi, I wonder if anybody can comment if what I see is normal in FW 1.1 and how to avoid this. I have .Net assembly, which creates literally thousands of temporary strings and other objects...
12
by: Mark P | last post by:
I wrote some code which makes heavy use of std::map. In fact, for a typical instance, I may have on the order of 100K maps, each with only a small number of elements. (In case you're curious,...
11
by: Marcus Jacobs | last post by:
Dear Group I have encountered a problem with fclose and I am wondering if anyone could provide some insight about this problem to me. Currently, I am working on a small personal project that is...
160
by: RG | last post by:
Greetings friends, This semester I have started a course in C programming. I was moving along fine until I reached to the topic of loops (feeling embarrassed among you elite programmers). My...
70
by: garyusenet | last post by:
I'm using an example piece of code: - namespace Wintellect.Interop.Sound{ using System; using System.Runtime.InteropServices; using System.ComponentModel; sealed class Sound{ public static...
113
by: John Nagle | last post by:
The major complaint I have about Python is that the packages which connect it to other software components all seem to have serious problems. As long as you don't need to talk to anything outside...
11
by: Vijaykumar Dave | last post by:
Is there anyone have calculator program with memory function ? I need it for submission of assignment. Vijaykumar Dave
50
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
1
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.