Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Objects in memory

Reply
Thread Tools

Objects in memory

 
 
rafal_@op.pl
Guest
Posts: n/a
 
      11-02-2007
class C1
{
int a;
void f();
}
class C2ublic C1
{
int b;
void f();
}

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

 
Reply With Quote
 
 
 
 
benben
Guest
Posts: n/a
 
      11-02-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> class C1
> {
> int a;
> void f();
> }
> class C2ublic C1
> {
> int b;
> void f();
> }


class definition must be terminated by a semicolon.

>
> 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
 
Reply With Quote
 
 
 
 
bhupendra yadav
Guest
Posts: n/a
 
      11-02-2007

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





(E-Mail Removed) wrote:

> class C1
> {
> int a;
> void f();
> }
> class C2ublic C1
> {
> int b;
> void f();
> }
>
> Memory:
> --------------------------
> Data of object C1
> int a;
> --------------------------
> --------------------------
> Data of object C2
> int b;
> --------------------------
> where are addresses of methods ?


 
Reply With Quote
 
Andrey Tarasevich
Guest
Posts: n/a
 
      11-02-2007
(E-Mail Removed) wrote:
> ...
> 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

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      11-02-2007
Andrey Tarasevich wrote:
> (E-Mail Removed) wrote:
>> ...
>> 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!

> --
> Best regards,
> Andrey Tarasevich
>

You sig is missing the space after the "--".

--
Ian Collins.
 
Reply With Quote
 
Andrey Tarasevich
Guest
Posts: n/a
 
      11-02-2007
Ian Collins wrote:
>>> ...
>>> 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
 
Reply With Quote
 
EventHelix.com
Guest
Posts: n/a
 
      11-03-2007
On Nov 2, 8:01 am, (E-Mail Removed) wrote:
> class C1
> {
> int a;
> void f();}
>
> class C2ublic 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Mike Larkin ASP .Net 1 05-23-2005 12:33 PM
Inheritance of objects within objects Simon Elliott C++ 2 12-10-2004 10:59 AM
Differences between Sony Memory Stick & memory Stick Pro vs Memory Stick Duo? zxcvar Digital Photography 3 11-28-2004 10:48 PM
objects of objects, vectors and sessions bigbinc Java 3 11-18-2003 09:26 AM



Advertisments