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.

Class footprint

D
Hello I'm learning C++ and having done some Asm and C.
I would like input on the following. If I understand what I'm
reading then Objects of a type of class gets a copy of it's class'
(including inherited classes) data members in memory for each
instance of an object.
But all the code, of objects of a type of class
(including inherited classes) is just one copy in memory to be
shared by all the Objects of that type of class.
Even with Virtual functions the same vtable is built and
shared between all objects of that type of class.
Right ? Wrong ? Please explain.

Jul 22 '05 #1
2 1756
D wrote:
Hello I'm learning C++ and having done some Assembler and C.
I would like input on the following.
If I understand what I'm reading,
then Objects of a type of class get a copy of it's class'
(including inherited classes)
[non static] data members in memory for each instance of an object.
A class is *not* an object. In Java,
an object with the same name as the class is always instantiated
when the class is defined but *not* in C++.
But all the code of objects of a type of class
(including inherited classes) is just one copy in memory
to be shared by all the Objects of that type of class.
Yes.
Objects, even Java objects, don't actually contain any functions.
Even with Virtual functions,
the same vtable is built and shared
[among] all objects of that type of class.
Right? Wrong? Please explain.
Right.
cat main.cc #include <iostream>

class X {
private:
// representation
int I;
public:
~X(void);
};

class Y {
private:
// representation
int I;
public:
virtual
~Y(void);
};

int main(int argc, char* argv[]) {
std::cout << sizeof(X)
<< " = sizeof(X)" << std::endl;
std::cout << sizeof(Y)
<< " = sizeof(Y)" << std::endl;
return 0;
}
g++ -Wall -ansi -pedantic -o main main.cc
./main

4 = sizeof(X)
8 = sizeof(Y)

An object of type Y has a hidden data member
which is a reference (pointer)
to the virtual function table (vtable) for class Y.
Jul 22 '05 #2
That's correct. The following articles describes the mapping with C and C++.

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

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

Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - System Architecture Design CASE Tool
Jul 22 '05 #3

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

Similar topics

6
by: Tom | last post by:
We have a VERY simple .NET C# Form Application, that has about a 23MB Memory Footprint. It starts a window runs a process and does a regular expression. I have done a GC.Collect to make sure that,...
11
by: dimension | last post by:
If my intentions are to create objects that encapsulates data rows in a table, is it better to use a Struct or Class? Based on what i read, if my objects will simply have get and set methods,...
3
by: Dean Slindee | last post by:
Is there a way to replace the commented out parameter add syntax with a single line of code, like the .Parameter.Add("@Letter"...) line below (which does not work)? 'Dim prmLetter As New...
8
by: Bob Dufour | last post by:
We got a windows form application that we wrote in VB.Net. Essentially its a manager for a list of persons and their contacts and some other info about the persons. No rocket science but lots of...
12
by: Varun Kacholia | last post by:
Apologies if this has been answered somewhere, but Google did not produce any concrete results. I would like to find out the memory footprint of a vector<T>. I tried to dig in the STL code and...
1
by: Felipe | last post by:
What comprises the on computers hosting non trivial.NET Windows Forms applications? Specifically, suppose I have developed a .NET 2.0 Windows Forms client and I've included a bunch of 3rd party...
5
by: cbbibleboy | last post by:
Hey, I've been getting some very strange results with what seems to be very simple code. All I'm doing is trying to use an STL vector of "cSprite"s -- a class I wrote. The problem arises when I try...
5
by: DBC User | last post by:
How would you develop a zero footprint application, is the smart client application a zero footprint application? Thanks.
14
by: =?GB2312?B?zPC5zw==?= | last post by:
Howdy, I wonder why below does not work. a = object() a.b = 1 # dynamic bind attribute failed... To make it correct, we have to create a new class: class MyClass(object): pass a =...
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
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
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
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.