Objects in memory

B

benben

class C1
{
int a;
void f();
}
class C2:public C1
{
int b;
void f();
}

class definition must be terminated by a semicolon.

Short answer: you need to do some research on memory management.

Slightly more elaborate answer:

When the compiler produces a program out of the source containing
classes C1 and C2, it saves the target code of C1::f and C2::f. When
the program is loaded by an operating system this piece of target code
is mapped into a piece of memory called static memory.

Only when the program instantiate an object of either C1 or C2, the
internal data C1::a and C2::a will be stored in memory. If the object is
global, namespace, static, then it will be put in the static memory. If
the object is a local object, it will be stored in the program stack.

Regards,
Ben
 
B

bhupendra yadav

Hi,

Whenever a Application is executed, it gets memory space inside Main
Memory, which is devided into several parts logically, from which two
parts are "Data Segment", "Code Segment".
So all the variables risides inside Data Segment.

And ALL METHODS RESIDES INSIDE CODE SEGMENT.
---------------------------------------------------------X-----x-------
X-----------------------------------------------------------
further queries are invited...
 
I

Ian Collins

Andrey said:
There are no "addresses of methods" there. What makes you think they
should be there in the first place?
Class methods are functions and functions have an address.

To the OP, the location of objects in memory isn't defined by the
standard, if you want to know the address of a member function, print it!
You sig is missing the space after the "--".
 
A

Andrey Tarasevich

Ian said:
Class methods are functions and functions have an address...

Just because something "has an address" doesn't mean that a question of
"where" is applicable to that address. In the context of the OP's
question it is clear [enough] that the "where" question he's asking is
applicable to lvalues only (since it is clear that his "where" actually
refers to memory locations). Nothing in the OP's post suggests the
existence of addresses of the methods as lvalues, hence my questions.
 
E

EventHelix.com

class C1
{
int a;
void f();}

class C2:public C1
{
int b;
void f();

}

Memory:

In most cases, methods are equivalent to C functions with the an
addition this pointer passed to them.

The following articles explain C++ constructs in terms of C code:

http://www.eventhelix.com/RealtimeMantra/basics/ComparingCPPAndCPerformance.htm

http://www.eventhelix.com/RealtimeMantra/basics/ComparingCPPAndCPerformance2.htm

--
EventStudio - http://www.Eventhelix.com/Eventstudio/
Sequence diagram based systems engineering tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top