shared_array with memcpy, help request
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? 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 }
Hello everyone :)
I am a new boost user, and I'm trying to convert a large project to use
smart pointers. I have a use for shared_array buy the memcpy line from
At 08:22 PM 3/24/2003, Blake D wrote: the 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 }
participants (2)
-
Beman Dawes
-
Blake D