[boost] Re: Re: optional: size optimization

2003-04-21 Thread Fernando Cacciola

Joel de Guzman [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 David B. Held wrote:
  Fernando Cacciola [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
  [...]
  I think I like this enhanced version.
  'max_size_type_that_fit_in_padding'
  must better be one of the intergral types
  to make easy and safe to use, so I guess that
  there might ocurr that some bits
  are wasted anyway.
 
  Why couldn't it be a char[]?

 char[] makes sense. Add a tag_size constant int and we're
 in business :-)

The reason why I discarded an array (or my problem with it, maybe)
is that it is difficult to get/set it because of
its semantics (array are not first class objects).

Furthermore, suppose there is no padding in a particular
implementation, how is the user supposed to allocate
the tag?
Of course, he can allocate it in its own structure, but he'll
need some awkward metaprogramming in such a case because
the tag will be either in the aligned_storage or somewhere
else.

I think that an usable solution, which might not exploit the
padding 100%, but which will be quite easy to use is this:

templateclass T, class tag_t
struct aligned_storage
{
  void const* address() const ;
  void*   address();

  // If tag_t fits in the padding, it is allocated there,
  // else it is allocated separately (but in here)
  tag_t const tag() const ;
  tag_t   tag();
}

Fernando Cacciola





___
Unsubscribe  other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Re: [boost] Re: Re: optional: size optimization

2003-04-21 Thread Joel de Guzman
Fernando Cacciola wrote:

 padding 100%, but which will be quite easy to use is this:
 
 templateclass T, class tag_t
 struct aligned_storage
 {
   void const* address() const ;
   void*   address();
 
   // If tag_t fits in the padding, it is allocated there,
   // else it is allocated separately (but in here)
   tag_t const tag() const ;
   tag_t   tag();
 }

Funny, that was my first prototype :o)...
Yes, that's very good, if it's possible to implement
I was concerned about, emmm...,  alignment issues.
I reckon tag_t type should be enforced to be an integral 
of some size.

-- 
Joel de Guzman
joel at boost-consulting.com
http://www.boost-consulting.com
http://spirit.sf.net

___
Unsubscribe  other changes: http://lists.boost.org/mailman/listinfo.cgi/boost