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

Objects in memory

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 ?

Nov 2 '07 #1
6 1429
ra****@op.pl wrote:
class C1
{
int a;
void f();
}
class C2:public 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
Nov 2 '07 #2

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:
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 ?
Nov 2 '07 #3
ra****@op.pl 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

Nov 2 '07 #4
Andrey Tarasevich wrote:
ra****@op.pl 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.
Nov 2 '07 #5
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
Nov 2 '07 #6
On Nov 2, 8:01 am, raf...@op.pl wrote:
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
Nov 3 '07 #7

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

Similar topics

16
by: Paul Rubin | last post by:
I've had this recurring half-baked desire for long enough that I thought I'd post about it, even though I don't have any concrete proposals and the whole idea is fraught with hazards. Basically...
1
by: Tony | last post by:
Hi, anyone have better information on IIS 5.0 memory behaviour on setting objects to nothing? Connections and recordsets of course should be set to nothing, but should for example XMLNode...
9
by: cppaddict | last post by:
I have a method that uses a fairly large object. The choice is between having a local object in the method or a static member object that the method uses. ------CHOICE 1--------- int...
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
100
by: E. Robert Tisdale | last post by:
What is an object? Where did this term come from? Does it have any relation to the objects in "object oriented programming"?
38
by: Radi Radichev | last post by:
Hi! I'm making a database application and i heard from a friend that it is more proffecional and easy to do this with bussines objects. Can anyone tell me where i can find more info on bussines...
14
by: luis | last post by:
Are basic types (int, long, ...) objetcs or not? I read that in C# all are objects including basic types, derived from Object class. Then in msdn documentation says that boxing converts basic...
8
by: vvenk | last post by:
Hello: I just wrote my first ASP.Net application. It worked fine on my machine and when I put into production, the ASP.Net process reaches 50% quite fast and then the system does not work...
2
by: Fish | last post by:
I have been researching the correct way to organize my solution so that it makes best use of VB.NET inherent ability to manage resources such as objects. My solution contains 2 projects and the...
15
by: Juha Nieminen | last post by:
I'm sure this is not a new idea, but I have never heard about it before. I'm wondering if this could work: Assume that you have a common base class and a bunch of classes derived from it, and...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.