Solved

Memory optimization

Posted on 2002-07-18
3
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Find boost header files using gnu make (MinGW) on Win 7 11 108
Arduino EDI - Programming language 3 124
C++ mouse_event mouse look 7 131
DCT of  2D array using fftw in c++ 9 125
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

738 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