Boost logo

Boost Users :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2003-03-25 07:04:22


At 08:22 PM 3/24/2003, Blake D wrote:
>Hello everyone :)
>
>I am a new boost user, and I'm trying to convert a large project to use
the
>smart pointers. I have a use for shared_array buy the memcpy line from
the
>following code snippet(, and all memcpy's) throw an exception with the
>shared_arrays and I don't know why. Am I doing something obvious wrong?

Do you ever do a r_packet.reset( new uint8[data_length] )? Put a debugger
breakpoint at entry to c_Packet, and see if r_packet has been reset.

HTH,

--Beman

>
>Thank you,
>Blake
>
>//------------------class declaration
>snippet---------------------------------
>// Pointer to the packet
>boost::shared_array<uint8> p_data;
>// uint8 * p_data; <--- old working line
>
>//------------------class cpp file
snippet---------------------------------
>// copy Constructor
>c_Packet::c_Packet (const c_Packet & r_packet)
>{
>data_length = r_packet.data_length;
>
>boost::shared_array<uint8> p_data(new uint8[data_length]);
>// p_data = new uint8[data_length]; <--- old working line
>
>// Copy data from our source object to this object
>memcpy(p_data.get(), r_packet.p_data.get(), data_length); // <- throws
>exception!
>// memcpy(p_data, r_packet.p_data, data_length); <---- old working line
>
>#ifdef DO_DEBUG
>// cout << "packet copy constructor called" << endl ;
>#endif // DO_DEBUG
>}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net