473,413 Members | 1,778 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,413 software developers and data experts.

Small dynamic objects and performance degradation.

What can I do to circumvent the performance degradation associated with
dynamic allocation and small objects? Thanks.
Jul 22 '05 #1
4 1909

"Jason Heyes" <ja********@optusnet.com.au> wrote in message
news:41**********************@news.optusnet.com.au ...
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

Jul 22 '05 #2
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

Jul 22 '05 #3
> 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.

Jul 22 '05 #4
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::pool - maybe that saves you some time.

bye,
'monster
Jul 22 '05 #5

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

Similar topics

2
by: Dave Brueck | last post by:
Below is some information I collected from a *small* project in which I wrote a Python version of a Java application. I share this info only as a data point (rather than trying to say this data...
2
by: Fuzzyman | last post by:
Looking at threading code it seems that the Global Interpreter Lock is a bit of a 'brute force' way of preventing two threads attempting to access sensitive objects simultaneously.... Why not...
13
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when...
0
by: Andrew Mayo | last post by:
This problem was discovered with MSDE2000 SP2 and under WinXP SP2. We are unsure whether it is more widespread as it has only been seen on one machine to date. The problem is related to name...
6
by: teedilo | last post by:
We have an application with a SQL Server 2000 back end that is fairly database intensive -- lots of fairly frequent queries, inserts, updates -- the gamut. The application does not make use of...
6
by: florian | last post by:
Hello, we are running DB2 UDB EEE Version 7.2 Fixpack 12 on a two machine Windows 2000 Advanced Server Cluster in a dss environment. Some dynamic sql statements for etl processes and even some...
48
by: Andrew Quine | last post by:
Hi Just read this article http://www.artima.com/intv/choices.html. Towards the end of the dicussions, when asked "Did you consider including support for the concept of immutable directly in C#...
22
by: Kevin Murphy | last post by:
I'm using PG 7.4.3 on Mac OS X. I am disappointed with the performance of queries like 'select foo from bar where baz in (subquery)', or updates like 'update bar set foo = 2 where baz in...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.