Solved

Memory optimization

Posted on 2002-07-18
3
213 Views
Last Modified: 2010-04-01
This may seem like an "obvious" or "beginner" question, but I've had no formal training in C++ programming, and I can't find any good information about this particular topic.

I create two classes, ie:  A Person class and a Car Class.
Each person will own two cars.
The car class will have a very small number of member variables (2 or 3), but a large number of functions (20 or 30).
There will be a large number of Person classes created at one time during the program, so there will be twice as many car classes created (2 for each person).

My question is:  How can I determine the memory footprint (not necessarily exactly, but generally) that is going to be taken up by each car class.  If it is going to be heavy because of all the functions, I want to find a different way of going about the whole process.
0
Comment
Question by:dirtdart
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 7163331
The functions (or better: methods) actuallydon't really contribute to the size, as they are stored only once. The "memory footprint" pretty much is determined by the data (member variables) that are stored. To find out about that, use

size_t sz = sizeof ( <datatype>);

The 'sizeof()' operator returns the size, in bytes, of any datatype or class.
0
 
LVL 5

Author Comment

by:dirtdart
ID: 7163336
Well that was quick and painless!  And believe it or not, exactly what I wanted to hear.  I was afraid that the methods would dramatically increase the size of the class, and in this case a large class taking up a lot of memory would be totally unacceptable.

Thanks
0
 
LVL 5

Author Comment

by:dirtdart
ID: 7163337
Well that was quick and painless!  And believe it or not, exactly what I wanted to hear.  I was afraid that the methods would dramatically increase the size of the class, and in this case a large class taking up a lot of memory would be totally unacceptable.

Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question