Binary tree

Hi, I am using a static array for a database that will be frequently searching / updated, but i would like to move to balance binary trees.But the constraint is that the processor consumes more time for dynamic memory allocation and hence it affects the speed.

So, kindly let me know a Binary tree that will help in overcoming the above problem ?

Thx in advans, Karthik Balaguru

Reply to
karthikbalaguru
Loading thread data ...

You can use a static buffer to allocate the nodes from. Since you were using a static array, I assume that your database is finite in size. Here is a static region allocator that can operate on a buffer of your choice:

formatting link

You may find it fairly useful. Also, you can use this in conjunction with a freelist which will give you the ability to reuse individual nodes, not just an entire region of them at a time.

Reply to
Chris M. Thomasson

ing

a

ust

How much percentage is this faster than malloc ?

(I have other related groups also in loop)

Thx in advans, Karthik Balaguru

Reply to
karthikbalaguru

What particular memory allocation algorithm do you have in mind? There are so many. Alls I can say is that if you pass the region allocator a buffer residing on the "stack", or even global buffer (e.g. threading aside for a moment), it will make ZERO system calls. Keep in mind that there are malloc implementation that have very little overheads; I have created some of them...

However, if your on an embedded system, I would simply create a static buffer, then create a fine-grained amount of regions, and feed offsets of the buffer to them. This can be made to work in certain scenarios. Region allocation is sort of a go between wart calling malloc/free on every allocation or GC. Regions are no silver bullet in any way, shape or form; its a simple tool. Use the right tool for the job.

Reply to
Chris M. Thomasson

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.