Connecting Tech Pros Worldwide Forums | Help | Site Map

Objects in memory

rafal_@op.pl
Guest
 
Posts: n/a
#1: Nov 2 '07
class C1
{
int a;
void f();
}
class C2:public C1
{
int b;
void f();
}

Memory:
--------------------------
Data of object C1
int a;
--------------------------
--------------------------
Data of object C2
int b;
--------------------------
where are addresses of methods ?


benben
Guest
 
Posts: n/a
#2: Nov 2 '07

re: Objects in memory


rafal_@op.pl wrote:
Quote:
class C1
{
int a;
void f();
}
class C2:public C1
{
int b;
void f();
}
class definition must be terminated by a semicolon.
Quote:
>
Memory:
--------------------------
Data of object C1
int a;
--------------------------
--------------------------
Data of object C2
int b;
--------------------------
where are addresses of methods ?
>
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
bhupendra yadav
Guest
 
Posts: n/a
#3: Nov 2 '07

re: Objects in memory



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...





raf...@op.pl wrote:
Quote:
class C1
{
int a;
void f();
}
class C2:public C1
{
int b;
void f();
}
>
Memory:
--------------------------
Data of object C1
int a;
--------------------------
--------------------------
Data of object C2
int b;
--------------------------
where are addresses of methods ?
Andrey Tarasevich
Guest
 
Posts: n/a
#4: Nov 2 '07

re: Objects in memory


rafal_@op.pl wrote:
Quote:
...
Memory:
--------------------------
Data of object C1
int a;
--------------------------
--------------------------
Data of object C2
int b;
--------------------------
where are addresses of methods ?
...
There are no "addresses of methods" there. What makes you think they
should be there in the first place?

--
Best regards,
Andrey Tarasevich

Ian Collins
Guest
 
Posts: n/a
#5: Nov 2 '07

re: Objects in memory


Andrey Tarasevich wrote:
Quote:
rafal_@op.pl wrote:
Quote:
>...
>Memory:
>--------------------------
>Data of object C1
>int a;
>--------------------------
>--------------------------
>Data of object C2
>int b;
>--------------------------
>where are addresses of methods ?
>...
>
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!
Quote:
--
Best regards,
Andrey Tarasevich
>
You sig is missing the space after the "--".

--
Ian Collins.
Andrey Tarasevich
Guest
 
Posts: n/a
#6: Nov 2 '07

re: Objects in memory


Ian Collins wrote:
Quote:
Quote:
Quote:
>>...
>>Memory:
>>--------------------------
>>Data of object C1
>>int a;
>>--------------------------
>>--------------------------
>>Data of object C2
>>int b;
>>--------------------------
>>where are addresses of methods ?
>>...
>>
>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...
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.

--
Best regards,
Andrey Tarasevich
EventHelix.com
Guest
 
Posts: n/a
#7: Nov 3 '07

re: Objects in memory


On Nov 2, 8:01 am, raf...@op.pl wrote:
Quote:
class C1
{
int a;
void f();}
>
class C2:public C1
{
int b;
void f();
>
}
>
Memory:
--------------------------
Data of object C1
int a;
--------------------------
--------------------------
Data of object C2
int b;
--------------------------
where are addresses of methods ?
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/RealtimeMa...erformance.htm

http://www.eventhelix.com/RealtimeMa...rformance2.htm

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


Closed Thread