Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Small dynamic objects and performance degradation.

Reply
Thread Tools

Small dynamic objects and performance degradation.

 
 
Jason Heyes
Guest
Posts: n/a
 
      12-13-2004
What can I do to circumvent the performance degradation associated with
dynamic allocation and small objects? Thanks.


 
Reply With Quote
 
 
 
 
Howard
Guest
Posts: n/a
 
      12-13-2004

"Jason Heyes" <(E-Mail Removed)> wrote in message
news:41bda3ef$0$1082$(E-Mail Removed) ...
> What can I do to circumvent the performance degradation associated with
> dynamic allocation and small objects? Thanks.
>


If you know how many of these items you might need (or the MOST you might
need), you could pre-allocate a pool of them at startup, and draw from that
pool. Or, you could allocate a larger chunk of memory, enough to hold a
number of the objects, and use "placement new" to construct the objects in
specific locations within that chunk. (But you might consider whether
you're actually observing any performance degradation, and profile it,
before you try to solve a problem that may not really exist.)

-Howard



 
Reply With Quote
 
 
 
 
Puppet_Sock
Guest
Posts: n/a
 
      12-13-2004
Jason Heyes wrote:
> What can I do to circumvent the performance degradation associated

with
> dynamic allocation and small objects? Thanks.


To put some flesh on the bones Howard provided:

You allocate a bunch of the small items in a pool some place.
There are many ways of doing this. One way is to put them in
a global object that does the maintenance for you. The global
object keeps them in an array or a vector or whatever is most
appropriate to your task. It will have various functions as
required to set things up, get the next available object,
give back an object, etc. Basically, you've got a special
purpose memory manager. Which brings up another way of
approaching this, namely to overload new and delete.

Then you need a "named constructor" to go with. That's just a
function in the class of the small object that allows you to
re-initialize the small object as required.

So, you allocate the global pool once. Then, as required, you
re-initialize each object to new values, possibly passing back
either a reference or a pointer, or possibly an iterator if
you have the pool in a standard container.

How fancy you get with this depends on your needs. For example,
you might do something along the lines of keeping the objects
along with a reference count of some kind, so you can keep track
of whether a given member of the pool is in use. Or you could
get really fancy and allow things like allocation of arrays of
the small object, initialization of ranges, etc.

And, as always with optimization issues, it is important to
actually test whether a new method actually works faster than
old methods. Get out your stop watch, design a typical test
case, and see if the pool actually makes things faster.
Socks

 
Reply With Quote
 
jcoffin@taeus.com
Guest
Posts: n/a
 
      12-13-2004
> What can I do to circumvent the performance degradation associated
> with dynamic allocation and small objects?


You might want to pick up a copy of _Modern C++ Design_ (Andrei
Alexandrescu), which contains a complete implementation of a
small-object allocator and a fair amount of discussion about
implementing and using same.

--
Later,
Jerry.

The universe is a figment of its own imagination.

 
Reply With Quote
 
Swampmonster
Guest
Posts: n/a
 
      12-14-2004
Jason Heyes wrote:
> What can I do to circumvent the performance degradation associated with
> dynamic allocation and small objects? Thanks.
>
>

Have a look at boost:ool - maybe that saves you some time.

bye,
'monster
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating dynamic objects with dynamic constructor args Greg Hoover Python 1 03-25-2008 04:12 PM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Small cameras getting too small? GRL Digital Photography 50 02-03-2006 03:12 AM
Small Square with small red X Peter Coddington Computer Support 4 01-03-2006 06:58 AM
poor performance when downloading small file using jrun dan Java 1 04-05-2004 11:19 PM



Advertisments