Re: [boost] Improved boost::any

10 Aug
2005
10 Aug
'05
8:14 a.m.
hello and good day to all, Well, I posted earlier about this, but yes, if you are going make a decent "any" with stack-allocation, you should let the maximum buffer size be variable. I didn't go into details about alignment or exceptions because I think it's pretty much old news. (In his article "Discriminated Unions", Andrei Alexandrescu considers all of this, however I don't totally agree with his implementation--too hairy for the 9-to-5 programmer.) My own recommendation is that both alignment and buffer size be adjustable. By default they should have sensible values. For example, 8 for both gives decent results on a lot of platforms, although you could do better with the help of sizeof and alignment_of. Besides simplifying the class definition, letting the programmer tweak alignment can be useful for types that can benefit from extra alignment. An example might be a character array--it only "needs" byte alignment, but maybe all of the string operations are tweaked for 32-bit alignment. Somebody made a rather interesting question, whether an object having size less than void * might need alignment greater than void *. Well, about the only maxim the C/C++ standards give is that alignment is platform dependent. In practice, I've never seen such a strange case. I think that sizeof(X) <= sizeof(Y) is a pretty good indicator that alignment(X) <= alignment(Y). (But remember, "minimum-acceptable" alignment is not the same as "optimum" alignment--my pentium lets me store and fetch a double at 0xDEADBEEF, but these operations aren't cheap!) Also, be careful with alignment_of: I remember it giving me some strange values on some illegal but idiomatic structures (e.g. zero-length arrays). If it gives you zero, put 8 or something you think is sensible. hope this helps On Tue, 09 Aug 2005 18:07:06 +0200, <boost-request@lists.boost.org> wrote: > Date: Tue, 09 Aug 2005 10:17:48 -0400 > From: christopher diggins <cdiggins@videotron.ca> > Subject: Re: [boost] Improved boost::any > To: boost@lists.boost.org > Message-ID: <026101c59ced$1ee4a3d0$2b792518@heronnest> > Content-Type: text/plain; format=flowed; charset=iso-8859-1; > reply-type=original > ----- Original Message ----- > From: "Vladimir Prus" <ghost@cs.msu.su> >> >> If the trick is to use "void*" pointer to data for storing data when >> it's >> small, then: >> >> - it's interesting to see performance comparison for any<string>, or >> any<some_other_large_class> > Another part of the optimization, is to avoid reallocating when > reassigning > any a different value with the same type. > On a related note: several people have suggested that a buffer should be > used with an arbitrary size set at compile time, which would help > significantly for container types. > >> - can't this be just patch to boost::any, as opposed to completely >> different >> class? > What does submitting a patch entail? Is that the way to go if the > implementation is completely different? > - Chriostopher Diggins -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
7247
Age (days ago)
7247
Last active (days ago)
0 comments
1 participants
participants (1)
-
felipe