[boost] Re: boost::any feature request
Vladimir Prus wrote: Aha, that's what I was trying to say, but not very clearly. Yes, *this* will work. But... it means that if you do any a1; anyfast_allocator a2 = a1; Then value stored in a2 will be allocated using a1's allocator, not a2's. Once any is created with a specific allocator, all copies will use the same allocator, which is doubtful behaviour. In the example above, the fast_allocator parameter has no effect at all. Even if this behavior is desirable, you don't need to add template parameter to 'any'. I agree, there is no need for the template parameter for any. You can add template parameter to 'holder' only, and another constructor, which allows to specify allocator. But then you can't make static_cast to holderKnownType, UnknownAllocator inside any_castKnownType(a); May be wrap allocator specific stuff into separate interface? There are two allocator types: (a) type specific ones like std::allocatorint and (b) catch-all allocators. Option (a) is probably better when you know the type: any a(1); // a uses new/delete any b(2, fast_allocatorint()); I don't know whether to leave the original allocator or replace it with another one while making a copy: any c(a); // c uses new/delete any d(b); // d uses fast_allocatorint? -- Alexander Nasonov Remove minus and all between minus and at from my e-mail for timely response ___ Unsubscribe other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
[boost] Re: boost::any feature request
Alexander Nasonov wrote: Vladimir Prus wrote: You can add template parameter to 'holder' only, and another constructor, which allows to specify allocator. But then you can't make static_cast to holderKnownType, UnknownAllocator inside any_castKnownType(a); May be wrap allocator specific stuff into separate interface? You can if you add one more level of inheritance: templateclass T, class Allocator class holder_with_allocator : public holderT // make static_cast to it { // ... }; There are two allocator types: (a) type specific ones like std::allocatorint and (b) catch-all allocators. Option (a) is probably better when you know the type: any a(1); // a uses new/delete any b(2, fast_allocatorint()); I don't know whether to leave the original allocator or replace it with another one while making a copy: any c(a); // c uses new/delete any d(b); // d uses fast_allocatorint? I forgot that we're allocating a memory for holderT not for type T. But there is a solution called rebind. So, I really don't know what to choose. -- Alexander Nasonov Remove minus and all between minus and at from my e-mail for timely response ___ Unsubscribe other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
[boost] Re: boost::any feature request
Hi Doug, Will I be able to write: anyfast_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 Sure you can. You just store a copy of the allocator along with the data you are holding. The holders would look like this: [...] virtual holder* clone() = 0 { holder* result = allocator.allocate(1); new (result) holder(value, allocator); return result; } Aha, that's what I was trying to say, but not very clearly. Yes, *this* will work. But... it means that if you do any a1; anyfast_allocator a2 = a1; Then value stored in a2 will be allocated using a1's allocator, not a2's. Once any is created with a specific allocator, all copies will use the same allocator, which is doubtful behaviour. In the example above, the fast_allocator parameter has no effect at all. Even if this behavior is desirable, you don't need to add template parameter to 'any'. You can add template parameter to 'holder' only, and another constructor, which allows to specify allocator. - Volodya virtual void destroy() = 0 { Allocator allocator(this-allocator); this-~holder(); allocator.deallocate(this); } }; This requires allocators to be CopyConstsructible, of course. Doug ___ Unsubscribe other changes: http://lists.boost.org/mailman/listinfo.cgi/boost ___ Unsubscribe other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
[boost] Re: boost::any feature request
Maxim Egorushkin wrote: 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. I can add it to dynamic_any. All that I need is just an allocator interface. It would be also nice not to use dynamic allocations at all for built-in types. -- Alexander Nasonov Remove minus and all between minus and at from my e-mail for timely response ___ Unsubscribe other changes: http://lists.boost.org/mailman/listinfo.cgi/boost