473,951 Members | 4,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pool question

I am creating a large graph object in which I add nodes whenever I
need them, and I create them by 'new node' individually. I know this
is slow if I am going to allocate thousands of nodes individually. I
want to replace this allocation by an allocation from a pool. One
simple method I can think of is a manual allocation of a large array
of nodes (since I have an estimate of how many nodes there will be),
and use pointers to array elements, and then of course keep track of
used nodes. I think I can do this easily because in my current version
there is no freeing of nodes (until the end, when everything is
freed), so it is manageable without writing a complicated pool
mechanism. But potentially such a simplistic method will be
inadequate. Moreover I am trying to make a transition to C++ from
another language, so I want to know how it is done in C++ style. So I
would like to know if there is some pool facility in the library. I
have seen that there is a Boost pool library but I don't know if it is
the simplest choice.
Oct 12 '08 #1
17 1631
a_linux_user wrote:
I am creating a large graph object in which I add nodes whenever I
need them, and I create them by 'new node' individually. I know this
is slow if I am going to allocate thousands of nodes individually. I
want to replace this allocation by an allocation from a pool. One
simple method I can think of is a manual allocation of a large array
of nodes (since I have an estimate of how many nodes there will be),
and use pointers to array elements, and then of course keep track of
used nodes. I think I can do this easily because in my current version
there is no freeing of nodes (until the end, when everything is
freed), so it is manageable without writing a complicated pool
mechanism. But potentially such a simplistic method will be
inadequate. Moreover I am trying to make a transition to C++ from
another language, so I want to know how it is done in C++ style. So I
would like to know if there is some pool facility in the library. I
have seen that there is a Boost pool library but I don't know if it is
the simplest choice.
First, I would change the code so that is uses an allocator instead of using
new and delete directly. You can test the code using the standard
allocator.

Then I would replace that allocator with a pool allocator. You can check out
various alternatives and also write your own. In the end, you can choose
the fastest.
Best

Kai-Uwe Bux
Oct 12 '08 #2
"a_linux_us er" <bd******@gmail .comwrote:
>
I am creating a large graph object in which I add nodes whenever I
need them, and I create them by 'new node' individually. I know this
is slow if I am going to allocate thousands of nodes individually. I
want to replace this allocation by an allocation from a pool. One
simple method I can think of is a manual allocation of a large array
of nodes (since I have an estimate of how many nodes there will be),
and use pointers to array elements, and then of course keep track of
used nodes. I think I can do this easily because in my current version
there is no freeing of nodes (until the end, when everything is
freed), so it is manageable without writing a complicated pool
mechanism. But potentially such a simplistic method will be
inadequate. Moreover I am trying to make a transition to C++ from
another language, so I want to know how it is done in C++ style. So I
would like to know if there is some pool facility in the library. I
have seen that there is a Boost pool library but I don't know if it is
the simplest choice.
Look for "operator new()" in your C++ manual(s) and on the net.
By this mechanism you can have your own allocator.

Oct 12 '08 #3
a_linux_user wrote:
I am creating a large graph object in which I add nodes whenever I
need them, and I create them by 'new node' individually. I know this
is slow if I am going to allocate thousands of nodes individually. I
want to replace this allocation by an allocation from a pool.
If all the nodes have the same size, you can use this:

http://warp.povusers.org/FSBAllocator/
Oct 12 '08 #4
On Sun, 12 Oct 2008 12:42:13 -0700 (PDT), a_linux_user
<bd******@gmail .comwrote:
>I am creating a large graph object in which I add nodes whenever I
need them, and I create them by 'new node' individually. I know this
is slow if I am going to allocate thousands of nodes individually. I
want to replace this allocation by an allocation from a pool.
Why not hold all your nodes in an std::vector, and refer to them by
subscript?

I've rarely felt the need for custom allocators. I usually just choose
data structures that don't need single-item allocation.

Oct 13 '08 #5
Thanks to all of you who responded. To begin with I am going to look
into using the standard allocator. Trying to read section 19.4 from
Stroustrup, but so far haven't figured how to use it. Later I will try
to post here little pieces of code to get your comments. Thank you
once again.
Oct 13 '08 #6
a_linux_user wrote:
Thanks to all of you who responded. To begin with I am going to look
into using the standard allocator.
I don't really understand what is it that you are going to gain from
that. The standard allocator does 'new' and 'delete' in the way you are
already doing.
Oct 13 '08 #7
a_linux_user wrote:
Thanks to all of you who responded. To begin with I am going to look
into using the standard allocator. Trying to read section 19.4 from
Stroustrup, but so far haven't figured how to use it. Later I will try
to post here little pieces of code to get your comments. Thank you
once again.
That may be an interesting learning exercise, but be forewarned that
standard allocators are not used consistently by different standard
library implementations . They're not anywhere near as useful as they
seem at first, unless you stick with a particular STL implementation.

Furthermore, it is often a waste of time to start optimizing constant
factors before you even have a working program. Since you're working
with graphs, the best places to improve performance (once your program
functions) will probably be in your search and traversal algorithms.
It's hard to optimize without profiling, and it's hard to profile
without working code. Make it right before you worry about making it fast.

My recommendation is to begin with create_node and destroy_node
functions that just use new and delete, and typedef'd pointers that are
either raw (e.g. typedef node* node_pointer; typedef node const*
node_const_poin ter;) or reference-counted (e.g. typedef
std::tr1::share d_ptr<nodenode_ pointer). If you really find that new
and delete are your performance bottleneck down the road, you can always
replace the use of new and delete with something fancier, without
breaking the syntax used in the rest of your program.
Oct 13 '08 #8
On Oct 13, 5:30*pm, Juha Nieminen <nos...@thanks. invalidwrote:
a_linux_user wrote:
Thanks to all of you who responded. To begin with I am going to look
into using the standard allocator.

* I don't really understand what is it that you are going to gain from
that. The standard allocator does 'new' and 'delete' in the way you are
already doing.
Thanks for pointing this out. I didn't realize that. I was always
under the impression that doing 'new' for each node was somehow bad.
Oct 13 '08 #9
On Mon, 13 Oct 2008 13:20:09 -0700 (PDT), a_linux_user
<bd******@gmail .comwrote:
>On Oct 13, 5:30*pm, Juha Nieminen <nos...@thanks. invalidwrote:
>a_linux_user wrote:
Thanks to all of you who responded. To begin with I am going to look
into using the standard allocator.

* I don't really understand what is it that you are going to gain from
that. The standard allocator does 'new' and 'delete' in the way you are
already doing.

Thanks for pointing this out. I didn't realize that. I was always
under the impression that doing 'new' for each node was somehow bad.
I think this is a language issue.

You need to look up custom allocators. The standard allocator *is* bad
(for some requirements), which is why it can be overridden using
custom allocators.

Both standard and custom allocators are accessed through the new
operator. This is because the new operator is responsible for calling
the constructor - not just allocating the memory.

Containers have defaulted template parameters that give a kind of
allocation policy ("policy" being a kind of template design pattern) -
it may be more appropriate to target this than the new operator.

Oct 14 '08 #10

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

Similar topics

9
7237
by: Philip Lawatsch | last post by:
Hi, I have some questions about whats written in http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.14 (Describing some memory pool) #1 From what i understand this will also work for new x and delete x, or did i misunderstand something ? and,
2
3376
by: VinDotNet | last post by:
Here's the Scenario I am facing: I've got a winform managed c++ client which connects to my managed COM+ server application (by making createinstance, then typecasting the object to an interface, then calling methods over it). This COM+ server application is from a C# dll that has references to Interop dlls (com type libraries written in unmanaged c++) and MC++ wrappers over unmanaged c++ code. I've got object pooling enabled with (Min : 0...
8
1826
by: ra294 | last post by:
I have an ASP.net application using SQL Server 2000 that every once in a while I am getting this error: "System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached" I looked at my code and It seems that I do close every connection that I open so I don't know why I am getting...
9
23104
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated to a pool. If I assign only one application to a applicaton pool and have multiple worker processes assigned to that pool. Will my application be processed by many worker processes?
5
3966
by: J-T | last post by:
I guess I'm a litte bit confused about app pool and worker process. In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated to a pool. If I assign only one application to a applicaton pool then: 1) Can I have multiple worker processes assigned to that pool? If yes,what is the advantage of doing so?
1
1254
by: henley.steve | last post by:
Hello, I have a problem with an application wherein the code as designed originally was not ensuring closing of connections when the application encountered an exception. I have fixed this and lesson learned there (ALWAYS enclose your connections in a TRY or a USING). Now, however, the pool appears to be reestablishing these connections
3
7551
by: Vlad Hrybok | last post by:
Hi all, I recently installed 64 bit version of Vista hoping to make it my primary development setup. I was able to do work with IIS7 and ASP.NET 2.0/Visua Studio 2005 combo, but hit a roadblock trying to work with Visual Studio .NET 2003 on ASP.NET 1.1 app. The problem is that I can’t create an application pool in IIS7 that would run .NET Framework 1.1. I noticed that unlinke .NET Framework 2.0, Framework 1.1 only gets installed...
3
4078
by: Venkat | last post by:
Hi, I am working on an application (developed using c#2.0) which needs to do a big job and when you start the job in a single thread it takes long time to complete. So, we want to break the job and run in multiple threads. I heard about .Net Thread pool class but it has some limitations like we can't have more than 25 threads in it and read some articles which explain the problems with the Standard thread pool in case any of thread throws...
5
4348
markrawlingson
by: markrawlingson | last post by:
Hey guys, Having a bit of a complicated issue here so please bare with me while I explain. I'm also not a system admin and don't know a whole lot about IIS, so i apologize in advance. I discovered this morning an inconsitency within the application pools of our website. Basically, we have a maze of cluttered folders and other gargabe within the website - with one main folder, called /secured/ running from the root of the website, which...
4
1602
by: Oriane | last post by:
Hello, I will soon installed a small Ajax Asp.Net "single page" site on a client site. This page is simply polling a Asp.Net Web service, which fetchs and returns parameters (temperature, air conditioning status...) to be displayed on the page. This is implemented with an Ajax Timer control server. Now this is my first "industrial" web site, and I'm concerned about its robustness. Do I need to create a specific pool on IIS 6 for the...
0
10174
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
11378
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10704
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8271
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6237
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6359
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3564
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.