```{index} single: B::COW ``` # B::COW ```{pperl-module-badges} B::COW ``` Ask whether a string shares its buffer copy-on-write, and how many scalars share it. perl copies a string by sharing its buffer and copying only when one of the copies is modified. These helpers expose that state, mostly to test code that wants to know a copy was avoided. ## Synopsis ```perl use B::COW qw(can_cow is_cow cowrefcnt cowrefcnt_max); my $a = "x" x 100; my $b = $a; # shares $a's buffer print is_cow($b) ? "shared\n" : "own\n"; print cowrefcnt($a), "\n"; # how many share it, as perl counts print cowrefcnt_max(), "\n"; # 255 ``` ## Functions `can_cow()` is true: this perl copies on write. `is_cow($sv)` is true for a string whose buffer is shared copy-on-write. `cowrefcnt($sv)` is the share count perl keeps in the buffer (0 for a shared hash key string, which has no such count), or `undef` for a value that is not copy-on-write. `cowrefcnt_max()` is the largest count, after which perl copies instead of sharing. Nothing is exported by default. This is a native implementation of B::COW 0.007's `COW.xs`; its `B/COW.pm` is used unchanged. ## Differences from upstream None. ## Functions ### Copy on write #### `can_cow` Whether this perl copies strings on write. **Synopsis** ```perl use B::COW qw(can_cow); print can_cow() ? "copy on write\n" : "plain copies\n"; ``` **What you get back** True: pperl, like perl 5.44, shares string buffers copy-on-write. #### [`is_cow`](COW/is_cow) Whether a string shares its buffer copy-on-write. #### [`cowrefcnt`](COW/cowrefcnt) How many scalars share a copy-on-write buffer, as perl counts. #### [`cowrefcnt_max`](COW/cowrefcnt_max) The largest copy-on-write share count. ```{toctree} :hidden: :maxdepth: 1 COW/is_cow COW/cowrefcnt COW/cowrefcnt_max ```