Pmt memory management

Hi Guys,

Does copying a large pmt vector involve copying the underlying memory
region or do they share a single copy (refcounted)? If the do share a
single memory area, then can one thread modify the data of the vector
and will it be visible to the other thread just like regular arrays?

Miklos

On Sat, Feb 22, 2014 at 1:49 PM, Miklos M.
[email protected] wrote:

Hi Guys,

Does copying a large pmt vector involve copying the underlying memory
region or do they share a single copy (refcounted)? If the do share a
single memory area, then can one thread modify the data of the vector
and will it be visible to the other thread just like regular arrays?

Miklos

Miklos,

PMTs are always managed as a shared pointer (refcounted using
boost::intrusive_ptr). So yes, you have to be careful with thread
safety. PMTs are designed to be read-only to avoid the thread safety
issue (for instance, when adding a key:value pair to a dictionary, you
actually return a new PMT dictionary). The vectors are the only (and
don’t ask me why…) PMT type that is directly writable. So yes, be
careful about thread safety issues with this structure.

Tom

Hi Tom,

Thanks for the clarification. I will be very careful, I promise :slight_smile:

Miklos

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs