Erik, Dean

On Tue, Feb 1, 2011 at 20:24, Nelson, Erik - 2
<[email protected]> wrote:
>
>> For data that's already in memory I get the utility of being able to
>> refer to the bytes directly. Unfortunately making the library
>> deallocate memory that the user allocated is, quite bluntly, bad form
>> and error prone.
>>
>> Makes sense?
>
> I'd say that passing ownership of an object to a library is neither bad form 
> nor error prone.  Sutter has a good writeup of
> using auto_ptr effectively in 'Exceptional C++' that seems applicable.  
> Transferring object ownership with auto_ptr is
> safe, efficient, and idiomatic.

I agree with this. Using auto_ptr to transfer ownership seems like a
no-brainer. However, it doesn't really solve the
transfer-data-without-copy problem, at least not entirely.

What if I have a char buffer I got out of some C API, and I'd like to
transfer that;

  char buffer[1024];
  unsigned long bufsize = sizeof(buffer) / sizeof(*buffer);
  GetUserNameA(buffer, &bufsize);

  // Now what?

I think in the cases where your data comes from somewhere out of your
control and it's not packed in an auto_ptr, you'll be just as screwed
as with the current std::string -- in order to get it transferable you
would have to reallocate it into an auto_ptr, and that might even
involve packing it into an auto_ptr< vector<T> >, which feels pretty
raw.

I don't have a good idea for how to solve the lifetime issues of the
payload, but an auto_ptr probably won't help (much) here.

Cheers,
- Kim

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Cpp-netlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cpp-netlib-devel

Reply via email to