Hi Pico,
I ran into the same limitation of object_pool in my own project.
Rather than mess with m4, I ended up sidestepping the problem like so:
void *mem = myPool.malloc();
Object *obj = new (mem) Object(arg1, arg2, etc.);
This works well for my use case because my Object's has no destructor,
so I can just call object_pool::free to free the memory, or wait until
the whole pool is destroyed. If you need destructors to run, you'll
have to do something like (untested):
obj->~Object();
myPool.free(obj);
-Gabe
On Thu, Aug 23, 2012 at 1:02 PM, Pico Geyer
Hi all.
I'm using object pools in some code of mine. The code needs to build on unix (gcc) and on Windows(Visual C++). The objects that I'm constructing take 4 arguments so I needed to use the scripts mentioned in the note on this page: http://www.boost.org/doc/libs/1_51_0/libs/pool/doc/html/boost/object_pool.ht...
<quote> Since the number and type of arguments to this function is totally arbitrary, a simple system has been set up to automatically generate template construct functions. This system is based on the macro preprocessor m4, which is standard on UNIX systems and also available for Win32 systems.
detail/pool_construct.m4, when run with m4, will create the file detail/pool_construct.ipp, which only defines the construct functions for the proper number of arguments. The number of arguments may be passed into the file as an m4 macro, NumberOfArguments; if not provided, it will default to 3.
For each different number of arguments (1 to NumberOfArguments), a template function is generated. There are the same number of template parameters as there are arguments, and each argument's type is a reference to that (possibly cv-qualified) template argument. Each possible permutation of the cv-qualifications is also generated.
Because each permutation is generated for each possible number of arguments, the included file size grows exponentially in terms of the number of constructor arguments, not linearly. For the sake of rational compile times, only use as many arguments as you need.
detail/pool_construct.bat and detail/pool_construct.sh are also provided to call m4, defining NumberOfArguments to be their command-line parameter. See these files for more details." </quote>
So I ran this script like so: ./pool_construct.sh 4 And I made sure that Visual C++ is using the right include directory. But I still get the error: error C2660: 'boost::object_pool<T>::construct' : function does not take 4 arguments
I then starting digging into the header files to see why pool_construct.ipp is not being included. I then found these two interesting parts in object_pool.hpp: #if defined(BOOST_MSVC) || defined(__KCC) # define BOOST_NO_TEMPLATE_CV_REF_OVERLOADS #endif
and #ifndef BOOST_NO_TEMPLATE_CV_REF_OVERLOADS # include
#else # include #endif I don't really understand why the pool_construct_simple.ipp file should instead be included for windows. But if there is a good reason for it, shouldn't the documentation be updated to tell you to instead run the pool_construct_simple.sh script instead? Can anyone provide any information to help me understand this?
Thanks in advance. Pico _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users