472,784 Members | 1,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 software developers and data experts.

Some perfomance thoughts required

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
Jun 27 '08 #1
4 1135
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
Jun 27 '08 #2
On Jun 20, 10:28*am, Erik Wikström <Erik-wikst...@telia.comwrote:
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::object_pool<T>.

T
Jun 27 '08 #3
In article <3d400f58-1b60-40dc-81bc-01e5e692fdcb@
59g2000hsb.googlegroups.com>, co*****@emiasys.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.
Jun 27 '08 #4
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
Jun 27 '08 #5

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

Similar topics

5
by: SuryaPrakash Patel via SQLMonster.com | last post by:
Dear Reader I am trying to design a database. How can I make best Judgement that Indexing (which I am trying to fix during Diagram Desingning process)is ok. I am able to identify the best...
4
by: numerous instabilities in deploying VB | last post by:
I have been working on a VB product It is working beautifuly on my XP dev box and my windows 2000 test machines in the lab. When I install at the customer site, I get all kinds of wacky problems...
10
by: George | last post by:
Hi, I have a report which shows all records from database into the browser. The final HTML comes out about 5 Meg. It takes 1 minute 5 seconds for transfer to show up when i hit the page with IE...
2
by: James T. | last post by:
Hello! Let's say I have 2 functions, both return data from the database. Now I would like to compare perfomance of these two functions. I would like to know how long it takes to execute these...
0
by: jambalapamba | last post by:
Hi I am removing node from a document depending on the style property and this is taking 7 seconds for checking complete document is there any ideas how can i improve the perfomance. Here is...
4
by: =?Utf-8?B?VmVlcmFiaGFkcmFpYWggTCBN?= | last post by:
Hi, I have two databases D1 with 6 million records and D2 with 95 thousand records. I need to check Common records from these two databases based on UserID and need to insert into other database...
3
by: damodharan | last post by:
Hello and thanks in advance. I have two table in DB2 (ver 8). table details are table one(Cust_det) has two fields (Cust_cin and cust_name). table two(cust_add_det) has cust_cin and...
2
by: MickJ | last post by:
Hi, I would like to write High perfomance server using C#. It would be desirable to hear offers and advices on this subject.
0
by: ferozanna | last post by:
I am using Asp.net 1.3 with C# My application used by call center people My applicaton is a three tier arch I have create data layer as class ibrary which goint to talke Ssqlserver 205 db ...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.