# Pmt memory management

**URL:** <https://www.ruby-forum.com/t/pmt-memory-management/239351>\
**Category:** GNU Radio\
**Created:** [February 22, 2014, 7:50pm UTC](https://www.ruby-forum.com/t/pmt-memory-management/239351 "2014-02-22T19:50:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [February 22, 2014, 7:50pm UTC](https://www.ruby-forum.com/t/pmt-memory-management/239351/1 "2014-02-22T19:50:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Miklos\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@Miklos\_M](https://www.ruby-forum.com/u/Miklos_M)\
**Post date:** [February 24, 2014, 4:17pm UTC](https://www.ruby-forum.com/t/pmt-memory-management/239351/2 "2014-02-24T16:17:25Z")

</div>

On Sat, Feb 22, 2014 at 1:49 PM, Miklos M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Miklos\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@Miklos\_M](https://www.ruby-forum.com/u/Miklos_M)\
**Post date:** [February 24, 2014, 4:21pm UTC](https://www.ruby-forum.com/t/pmt-memory-management/239351/3 "2014-02-24T16:21:32Z")

</div>

Hi Tom,

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

Miklos
