Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2006-05-18 12:38:06

Asger Mangaard wrote:
> Tobias Schwinger wrote:
>>o save a few lines for "deep compare" (it seems unlikely to me that this
>>feature will be very useful)

Unfortunately the context got lost, here:
That point is from my summary of what the library seems to buy me in its current state.

> Would you rather compare on the pointers themselves, or?

Not neccessarily (but it seems a more approriate default to me, while we're at it).
Why bother with comparison in the first place?

>>o stack allocation using SBO
> Could be interresting.

...and can probably done with STL-style allocator support. Something like that

  namespace my_project
    // customize boost::body_ptr for my_project's memory management
    template<typename T>
    struct body_ptr
      : boost::body_ptr<T, my_custom_allocator<T> >
    { };

should work, however, so the user does not have to repeat the parametrization all over the place.

>>o COW (copy on non const access)
> Could you give an example?

Let's see (untested and incomplete code for illustration only):

  class my_class
     struct heavy_body;
     body_ptr< heavy_body > ptr_body;

     state get_state() const;
     void set_state(state);

  // ...

  my_class my_instance;
  // ...
  my_class my_second_instance(my_instance);
  // no copy, both instances share the same body

  #if case1

  // non-const access of shared body ==> need a copy
  // my_second_instance gets a brand new copy

  #elif case2

  // non-const access of shared body ==> need a copy
  // my_instance gets a brand new copy


Works for you?

Note that you have to synchronize the reference counter and also the copy operation in a multithreaded environment.



Boost list run by bdawes at, gregod at, cpdaniel at, john at