?
Solved

Memory optimization

Posted on 2002-07-18
3
Medium Priority
?
233 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 800 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

850 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