Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr question
From: David Michael Bond (david.bond_at_[hidden])
Date: 2010-05-18 13:06:35


> Defer this declaration " boost::shared_ptr<Frame> rx" in following way and
see if that helps ...
> boost::shared_ptr<Frame> &rx = processing_queue.back( ) ;

This prevents the segfault, but I'm very curious about what was causing it.
Any insight on the fundamental misuse?

> Why not just assign?
> last_rx_frame = new Frame;

Last_rx_frame is a shared_ptr. That assignment is invalid. I have done it
without a reset (creating and assigning a new shared_ptr and that has no
effect.

> last_rx_frame->bytes.reset( new u_char[size]) ;
> Is last_rx_frame->bytes also a shared_ptr? According to boost docs, a
shared_ptr shouldn't be used to hold a dynamically allocated array; you
should use shared_array instead. Just a shot in the dark.

last_rx_frame->bytes is a shared_array.

Thanks for the help so far guys!

I looked into it more and it seems if I comment out the memcpy in the
get_ether_header function I do not get the segfault.

ether_header Frame::get_ether_header( ) {
  ether_header ret ;
  memcpy( &ret, this->bytes.get(), this->size ) ;
  return ret ;
}

Its fine to return that stack var right there right? That should just copy
the memory into the return value for the stack?

-David


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