Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-03-24 02:25:12


Hi Maxim,
> I think it would be great to make boost::any's memory allocation
> strategy for value holder customizable. It would allow to use not only
> global new operator, but any other special fast allocators like, for
> example, Loki::SmallObject.
>
> The changes are minor and would not break existing code.
>
> All it takes is to change class name and:
>
> struct use_default_allocator {};
>
> //class any
>
> template<class A = use_default_allocator> class any_ex
>
>
> And change any_cast functions appropriately.

Say, I have

   std::map<std::string, boost::any> values;

Will I be able to write:

   any<fast_allocator> a;
   values[10] = a;

?
IOW, I don't think your proposal provides any means to convert between 'any'
with different allocators. And I'm not sure you can easily achieve that....

>
> I've measured performance using Intel VTune. The
> any_ex<Loki::SmallObject> was about twice as fast as any_ex<> with MS
> VC++ 7 and Intel C++ 7.

On what testcase?

> So, the hardcoded memory allocation strategy makes more harm then good
> to boost::any. Changes would make boost::any more extensible and
> reusable.

Unless there's a way to convert between different any's, the idea is
questionable. Say, a library uses 'any' in interface. It certainly uses
default allocator, and without conversion, will impose that default allocator
on client code. IOW, you cannot write

   any<fast_allocator> a = some_lib::get_value("foo");

- Volodya

P.S. And, BTW, it would be great to see the complete code that you propose (or
a diff to CVS HEAD).


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