Boost logo

Boost :

From: hicks (hicks_at_[hidden])
Date: 2002-04-28 01:19:22


To David White

I did not realize that there would be a seperate allocator for each
object size.
Is that right?

I am having some trouble getting var_len_array.hpp and the test package
to compile under borland.

I had to elise the line

#ifndef __BORLANDC__
template<std::size_t ObjSize>
detail::stack_allocator_impl<ObjSize> stack_allocator<ObjSize>::instance;
#endif

in order to compile up to link.

But link fails because it cannot then find an instance of "instance".

I tried declaring instance at the top of the test file,

boost::stack_allocator<1>::instance sai1;

which is is a hack anyway, but then the compiler complains about repeat
declaration,
the first being

template<std::size_t ObjSize>
class stack_allocator
{
static detail::stack_allocator_impl<ObjSize> instance; <<-------- here
is first declaration
public:
static void* push(std::size_t nobjects) { return instance.push(nobjects); }
static void pop(void* ptr, std::size_t nobjects) { instance.pop(ptr,
nobjects); }
};

as indicated.

I can think of the following workaround:

In a unique cpp file, there is a declaration of a shared pointer to a
singleton stack_allocator_impl,
and a function to make copies of that pointer, which will initialize the
pointer (via new) on the first call.
(This requires user cooperation, perhaps including a single macro line
somewhere in a lone cpp file linked
to the project).

On creation, each allocator obtains a shared pointer to the singleton
stack_allocator_impl, which it
keeps during the duration of its lifetime, and uses to access push() and
pop().

Or, it could just be a plain pointer, since the objects are supposed to
be stack objects anyway,
and lifetime issues should not be of concern.

The user cooperation part may make this unacceptable.

Craig Hicks

/Message: 12
/From: David White <dave_at_[hidden]> <mailto:dave_at_[hidden]>
/To: boost_at_[hidden] <mailto:boost_at_[hidden]>
/Date: 20 Apr 2002 16:10:26 +1000
/Subject: [boost] Preliminary Submission of var_length_array
/Reply-To: boost_at_[hidden] <mailto:boost_at_[hidden]>

/I have written a preliminary implementation of my idea for a
/variable-length array class template. It's been renamed to
/var_length_array, due to comments about potential confusion with
/valarray.

/The files, including some basic documentation and a test suite, can be
/found at http://groups.yahoo.com/group/boost/files/var_length_array/

/Comments and feedback are of course, most welcome.

/David.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk