Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Some perfomance thoughts required

Reply
Thread Tools

Some perfomance thoughts required

 
 
Alexander Adam
Guest
Posts: n/a
 
      06-20-2008
Hi!

I've got a pretty complex data structure that keeps instances of
structs allocated with the new operator.
Now my issue is that those structures are required to be allocated /
deallocated pretty often resulting
in a huge perfomance issue. Usually what I am doing is to create
arrays and initialize their sizes a few
times bigger than originally required to avoid another allocation on
the next run. Then I do simply reset them
and do a memcpy at the existing location. This works great with POD
structus but my structs are complex
in the way that they not only use inheritance but they do also use
internal objects that do require an
constructor / destructor. So what is the general way to handle such
things? Am I missing something?

thanks!
Alex
 
Reply With Quote
 
 
 
 
Erik Wikström
Guest
Posts: n/a
 
      06-20-2008
On 2008-06-20 11:05, Alexander Adam wrote:
> Hi!
>
> I've got a pretty complex data structure that keeps instances of
> structs allocated with the new operator.
> Now my issue is that those structures are required to be allocated /
> deallocated pretty often resulting
> in a huge perfomance issue. Usually what I am doing is to create
> arrays and initialize their sizes a few
> times bigger than originally required to avoid another allocation on
> the next run. Then I do simply reset them
> and do a memcpy at the existing location. This works great with POD
> structus but my structs are complex
> in the way that they not only use inheritance but they do also use
> internal objects that do require an
> constructor / destructor. So what is the general way to handle such
> things? Am I missing something?


A pool allocator might help.

--
Erik Wikström
 
Reply With Quote
 
 
 
 
tommy.hinks@gmail.com
Guest
Posts: n/a
 
      06-20-2008
On Jun 20, 10:28*am, Erik Wikström <Erik-wikst...@telia.com> wrote:
> On 2008-06-20 11:05, Alexander Adam wrote:
>
>
>
> > Hi!

>
> > I've got a pretty complex data structure that keeps instances of
> > structs allocated with the new operator.
> > Now my issue is that those structures are required to be allocated /
> > deallocated pretty often resulting
> > in a huge perfomance issue. Usually what I am doing is to create
> > arrays and initialize their sizes a few
> > times bigger than originally required to avoid another allocation on
> > the next run. Then I do simply reset them
> > and do a memcpy at the existing location. This works great with POD
> > structus but my structs are complex
> > in the way that they not only use inheritance but they do also use
> > internal objects that do require an
> > constructor / destructor. So what is the general way to handle such
> > things? Am I missing something?

>
> A pool allocator might help.
>
> --
> Erik Wikström


Check out boost:bject_pool<T>.

T
 
Reply With Quote
 
Jerry Coffin
Guest
Posts: n/a
 
      06-20-2008
In article <3d400f58-1b60-40dc-81bc-01e5e692fdcb@
59g2000hsb.googlegroups.com>, says...
> Hi!
>
> I've got a pretty complex data structure that keeps instances of
> structs allocated with the new operator.
> Now my issue is that those structures are required to be allocated /
> deallocated pretty often resulting
> in a huge perfomance issue. Usually what I am doing is to create
> arrays and initialize their sizes a few
> times bigger than originally required to avoid another allocation on
> the next run. Then I do simply reset them
> and do a memcpy at the existing location. This works great with POD
> structus but my structs are complex
> in the way that they not only use inheritance but they do also use
> internal objects that do require an
> constructor / destructor. So what is the general way to handle such
> things? Am I missing something?


You probably want to overload operator new for the class(es) of the
objects you're allocating/freeing so frequently. At startup, your
operator new will grab a big chunk of memory for the data, and break it
up into chunks, each the size of a single object. As objects are
allocated, it'll give out the addresses of object-sized chunks, and mark
each chunk as being in use when it does so. When an object is freed,
it'll mark each chunk as being available again.

You can probably find existing source code for a few different versions
of this -- Andrei Alexandrescu's Loki library has one, and Boost has
another, and so on.

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
Fei Liu
Guest
Posts: n/a
 
      06-20-2008
Alexander Adam wrote:
> Hi!
>
> I've got a pretty complex data structure that keeps instances of
> structs allocated with the new operator.
> Now my issue is that those structures are required to be allocated /
> deallocated pretty often resulting
> in a huge perfomance issue. Usually what I am doing is to create
> arrays and initialize their sizes a few
> times bigger than originally required to avoid another allocation on
> the next run. Then I do simply reset them
> and do a memcpy at the existing location. This works great with POD
> structus but my structs are complex
> in the way that they not only use inheritance but they do also use
> internal objects that do require an
> constructor / destructor. So what is the general way to handle such
> things? Am I missing something?
>
> thanks!
> Alex

Apart from the other suggestions, you should think about the use of
array as your container data structure, perhaps a node based container
will provide better overall performance, especially when it's memory
intensive.

Fei
 
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
data perfomance? Scott Reynolds ASP .Net 3 03-01-2005 01:54 PM
CreateInstranceAndUnwrap slow perfomance Gnanaprakash Rathinam ASP .Net 5 12-30-2004 09:18 PM
Server perfomance Fredrik Melin ASP .Net 1 10-27-2004 11:45 AM
perfomance an ip-route-cache on a router Ralf Huelsmann Cisco 1 08-15-2004 03:09 PM
Optimizing perfomance on T3 line Christoph Schad Cisco 12 01-01-2004 08:40 PM



Advertisments