This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] Slightly better way to __USE_MALLOC
On Thu, Oct 10, 2002 at 06:33:42PM -0400, Phil Edwards wrote:
> On Thu, Oct 10, 2002 at 07:22:36PM -0300, Brad Spencer wrote:
> >
> > The symbols I'm talking about aren't new. __default_alloc_template
> > and __malloc_alloc_template already exist and are already both in the
> > GLIBCPP_3.2 version. I think it would make sense to rename __default
> > to __pool, but it's probably too late for that now.
>
> Too late for the 3.2 series, but nobody's expecting the library to have
> the same ABI for 3.[34]. There're still too many useful changes to make.
> Like this one. :-)
Ok! I've changed __default_alloc_template to __pool_alloc_template
and instantiated both.
> On my whiteboard I have a Grand Master Plan to reorganize the stl_alloc.h
> header, making things more generic, and allowing multiple allocation
> schemes to be instantiated in the library. For it, I was freely changing
> the names of the internal classes.
Hopefully what I am playing with here is working towards that goal and
not against it.
> Then you can in theory write
>
> std::vector<foo,the_malloc_allocator> x;
> std::vector<foo,the_default_allocator> y;
>
> without needing to carry around instantiations of one of those allocators
> in your code, which is wasteful at best and could lead to multiple symbol
> definitions at worst.
Mmmm. Yes. If everything uses rebind (I think it does), then the
following should do the trick:
#ifdef _GLIBCPP_USE_MALLOC
typedef allocator<void> __malloc_allocator;
typedef __allocator<void, __pool_alloc_template<true, 0> >
__pool_allocator;
#else /* _GLIBCPP_USE_MALLOC */
typedef __allocator<void, __malloc_alloc_template<0> >
__malloc_allocator;
typedef allocator<void> __pool_allocator;
#endif /* _GLIBCPP_USE_MALLOC */
But that might wastefully instantiate __allocator<void, ...>. If
that's problematic, that might mean something like:
template<typename _Tp>
struct __allocator_select
{
#ifdef _GLIBCPP_USE_MALLOC
typedef __allocator<_Tp, __pool_alloc_template<true, 0> >
pool_allocator_type;
typedef allocator<_Tp> malloc_allocator_type;
#else /* _GLIBCPP_USE_MALLOC */
typedef allocator<_Tp> pool_allocator_type;
typedef __allocator<_Tp, __malloc_alloc_template<0> >
malloc_allocator_type;
#endif /* _GLIBCPP_USE_MALLOC */
};
--
------------------------------------------------------------------
Brad Spencer - spencer@infointeractive.com - "It's quite nice..."
Systems Architect | InfoInterActive Corp. | A Canadian AOL Company