|
-
November 19th, 2008, 06:45 PM
#1
Heap efficiency?
I wonder how efficient is the C++ heap generally?
Say I would like to create in the order of 1 million quite small objects quite frequently. Is the ordinary C++ heap fit to handle this, or will it be like wading in a tar pit?
I know I should measure and see if it's a performance bottleneck in my specific program, but I'm looking for a more general assessment. If you're programming in the OO style is the C++ heap likely to become a bottleneck and you should seek aid in a specialized object allocator or even a garbage collector?
-
November 19th, 2008, 08:59 PM
#2
Re: Heap efficiency?
 Originally Posted by _uj
I wonder how efficient is the C++ heap generally?
This all depends on the compiler and implementation.
Regards,
Paul McKenzie
-
November 19th, 2008, 09:19 PM
#3
Re: Heap efficiency?
With *proper design* heap performance should never be an issue.
For some recommendations on heaps and small object allocation see here
ps: Paul 100% correct in that it WILL vary, and MEASUREMENT against a DEFINED REQUIREMENT is key to any analysis of performance.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
November 19th, 2008, 10:28 PM
#4
Re: Heap efficiency?
 Originally Posted by Paul McKenzie
This all depends on the compiler and implementation.
Regards,
Paul McKenzie
Do you mean that with SOME compiler and with SOME object usage this ceases to be a problem?
Then it would be interesting to hear your advice as to WHAT compiler one should use and to HOW one's objects should be managed.
-
November 19th, 2008, 10:32 PM
#5
Re: Heap efficiency?
 Originally Posted by _uj
Do you mean that with SOME compiler and with SOME object usage this ceases to be a problem?
What I'm saying is that the heap manager is written by the compiler vendor. There are many ways to write a heap manager -- look up best fit, first fit, etc.
Then it would be interesting to hear your advice as to WHAT compiler one should use and to HOW ones objects should be managed.
That is your research project.
Regards,
Paul McKenzie
-
November 19th, 2008, 10:36 PM
#6
Re: Heap efficiency?
 Originally Posted by TheCPUWizard
With *proper design* heap performance should never be an issue.
Do you mean C++ programs should better be designed to avoid heap allocations?
-
November 19th, 2008, 10:41 PM
#7
Re: Heap efficiency?
 Originally Posted by Paul McKenzie
What I'm saying is that the heap manager is written by the compiler vendor. There are many ways to write a heap manager -- look up best fit, first fit, etc.
That is your research project.
No it's not my research project. I've done my research (test me if you like).
What I'm asking is if you have something to contribute on this matter (besides the general bullshit)?
-
November 19th, 2008, 10:53 PM
#8
Re: Heap efficiency?
 Originally Posted by _uj
Do you mean C++ programs should better be designed to avoid heap allocations?
Certainly they should be designed to avoid overusing heap allocations. Often you can write lots of code without ever using a new call. If heap allocation is done internally by an STL container or something don't worry about it, though.
-
November 19th, 2008, 11:05 PM
#9
Re: Heap efficiency?
 Originally Posted by _uj
What I'm asking is if you have something to contribute on this matter
And I did just that. Heap managers performance and efficiency depends on the compiler's implementation.That's my point -- there is no such thing as an "ordinary C++ heap".
I don't know how old you are, but in the days when there were compiler wars between Microsoft, Borland, Watcom, etc. the efficiency of the heap was a major selling point, emphasizing the fact that heap performance was (and is) highly dependent on the implementation.
That is why I stated you do the research on what compiler has to offer in terms of heap performance. I am not paid to do this.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; November 19th, 2008 at 11:07 PM.
-
November 19th, 2008, 11:29 PM
#10
Re: Heap efficiency?
 Originally Posted by Lindley
Certainly they should be designed to avoid overusing heap allocations. Often you can write lots of code without ever using a new call. If heap allocation is done internally by an STL container or something don't worry about it, though.
What exactly do you mean by "designed to avoid overusing heap allocations"?
To me it suggests you consider possible heap allocations an important design criterion. Do you?
-
November 19th, 2008, 11:38 PM
#11
Re: Heap efficiency?
 Originally Posted by _uj
Do you mean C++ programs should better be designed to avoid heap allocations?

I amn saying that any piece of software can be effectively used or it can be mis-used. he book I referenced contains published,proven and accepts techniques to be effective.
ps: That is only one section of this book, which I firmly believe should be read and understood by every serious C++ programmer [typically after reading all of Scott Meyers' books]. The only caution I give is the intermediate programmers should wear a helmet while reading as this will minimze the mess should their head literally explode (the more advanced programmer may simply need a large bottle of extra strength headache medicine.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
November 26th, 2008, 08:40 PM
#12
Re: Heap efficiency?
Well, the question of the efficiency/ineff*ciency of the C++ heap definately deserves a discussion.
For the time being, extensive usage of the C++ heap, is a big "no no" right?
-
November 26th, 2008, 08:52 PM
#13
Re: Heap efficiency?
 Originally Posted by _uj
Well, the question of the efficiency/ineff*ciency of the C++ heap definately deserves a discussion.
For the time being, extensive usage of the C++ heap, is a big "no no" right?
Not at all, at least not in any project I have worked on in the last decade....Provided proper care is taken regarding object lifetime management, heap fragmentation, and a few other issues.
Even in projects such as real-time control of industrial robotics or highspeed communications [eg where keys change at rates of 1Khz or more] the heap has not beome an actual issue.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
November 26th, 2008, 09:18 PM
#14
Re: Heap efficiency?
 Originally Posted by TheCPUWizard
Not at all, at least not in any project I have worked on in the last decade....Provided proper care is taken regarding object lifetime management, heap fragmentation, and a few other issues.
Are you able to raise beyond yourself and consider the general problem?
-
November 27th, 2008, 10:03 AM
#15
Re: Heap efficiency?
 Originally Posted by _uj
Are you able to raise beyond yourself and consider the general problem?
Did YOU read the material I posted back in reply #3. It goes into complete details (many pages alongwith other references) that are simply impractical to cover in a simple forum post.
In summary.
1) Be careful about object lifetime. Are you calling new/delete at the most efficient times? Can you "re-use" blocks instead of returning them to the general heap?
2) Be careful about heap fragmentation. Are you alloction sizes consistant? If you are allocating many differing size blocks it (potentially) complicates the heap structures.
3) Measure the amount of time (and locations in the program) where you are doing the new/delete.. One of the simplest ways to do this is to override the globl new/delete (I use a technique similar to what VC++ does for "_DEBUG" configurations). Can you changing the timing to be more efficient?
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|