473,399 Members | 2,278 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,399 software developers and data experts.

What's better, Big classes or Small

Let's ignore for a minute design decisions , readability and any other
of those parameters , In the most raw form of c++ (purely efficiency
if you want)
what is better, bloating up a classes or breaking them up to small
classes?
(and again pure efficiency of the compiler)
Thanks
Aug 27 '08 #1
6 2547
On 27 Aug, 10:35, ManicQin <Manic...@gmail.comwrote:
Let's ignore for a minute design decisions , readability and any other
of those parameters , In the most raw form of c++ (purely efficiency
if you want)
what is better, bloating up a classes or breaking them up to small
classes?
(and again pure efficiency of the compiler)
skip the compiler and write it directly in machine code

--
Nick Keighley
Aug 27 '08 #2
Nick Keighley wrote:
On 27 Aug, 10:35, ManicQin <Manic...@gmail.comwrote:
Let's ignore for a minute design decisions , readability and any other
of those parameters , In the most raw form of c++ (purely efficiency
if you want)
what is better, bloating up a classes or breaking them up to small
classes?
(and again pure efficiency of the compiler)

skip the compiler and write it directly in machine code

--
Nick Keighley
01000001 01110011 01110011 00100000 01001000 01101111 01101100
01100101 ...
Aug 27 '08 #3
ManicQin wrote:
Let's ignore for a minute design decisions , readability and any other
of those parameters , In the most raw form of c++ (purely efficiency
if you want)
what is better, bloating up a classes or breaking them up to small
classes?
(and again pure efficiency of the compiler)
The biggest factor in execution speed of a large program are design
decisions and readability. Anything else is something the profiler will
tell you about.
Aug 27 '08 #4
ManicQin wrote:
Let's ignore for a minute design decisions , readability and any other
of those parameters , In the most raw form of c++ (purely efficiency
if you want)
what is better, bloating up a classes or breaking them up to small
classes?
(and again pure efficiency of the compiler)
What do you mean by "pure efficiency of the compiler"? How fast the
compiler can compile your source files?
Aug 27 '08 #5
ManicQin <Ma******@gmail.comwrites:
Let's ignore for a minute design decisions , readability and any other
of those parameters , In the most raw form of c++ (purely efficiency
if you want)
what is better, bloating up a classes or breaking them up to small
classes?
(and again pure efficiency of the compiler)
Neither big or small. Medium sized classes.

The point is that both human programmers, and modern processors are
sized to handle efficiently in short term memory (L1-cache) a medium
number of items. That is, betweeen 5 and 9, 7 on average.

That's the average number of data member a object shall have,
(multiply by 2 to 4 times for the number of methods).

Of course, you may have exceptions, with one or zero data, or with 40
data fields, but you would have to give a very strong reason why not
store the 40 data into a dictionnary, and why not remove the class
with one data member and using directly the data.
Otherwise, for the question of efficiency of the compiler, by the time
your program is termined (and this will be farther in the future the
more you think about performace in these terms), the hardware will
have evolved in such a way and magnitude, that any step you could have
made toward that efficiency would be totally irrelevant (and possibly
counter productive).

--
__Pascal Bourguignon__
Aug 27 '08 #6
ManicQin <Ma******@gmail.comkirjutas:
Let's ignore for a minute design decisions , readability and any other
of those parameters , In the most raw form of c++ (purely efficiency
if you want)
what is better, bloating up a classes or breaking them up to small
classes?
(and again pure efficiency of the compiler)
You can bloat up classes either by adding a lot of member functions, or
by adding a lot of data members.

The number of member functions should not have any impact on program
speed. If they are virtual, the vtable fo the class gets bigger, but a
number of vtables for split-up objects would make up the same, so there
is no difference. For non-virtual functions there should be no difference
wahtsoever.

The number of data members in the class should not make any difference as
well. If they are in the separate classes the total amount of memory
would be the same. When processing arrays of objects, smaller classes may
have better cache locality. OTOH, if your processing would involve
accessing different classes/arrays all the time, this might not be a win.

The solution: design your classes to be most maintainable. If there is a
performance issue, profile the code, find the bottlenecks and fix them.
Serious bottlenecks are caused by wrong algorithms, not by the class
layout.

hth
Paavo
Aug 27 '08 #7

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
12
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. ...
31
by: N.Davis | last post by:
I am very new to Python, but have done plenty of development in C++ and Java. One thing I find weird about python is the idea of a module. Why is this needed when there are already the ideas of...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
3
by: Paul | last post by:
Hello, I'm upgrading a small single user app to VB.NET and have a few questions about loading classes & collections classes with the data from a one to many dataset structure. I'm serializing...
11
by: John Salerno | last post by:
From my brief experience with C#, I learned that it was pretty standard practice to put each class in a separate file. I assume this is a benefit of a compiled language that the files can then be...
15
by: jim | last post by:
Maybe I'm missing something, but it doesn't look like Microsoft writes a lot of apps in .Net (although they certainly push it for others). What does MS write using pure .Net? If applications...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.