Solved

Memory optimization

Posted on 2002-07-18
3
188 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now