Data::COW - clone deep data structures copy-on-write


Data-COW documentation  | view source Contained in the Data-COW distribution.

Index


NAME

Top

Data::COW - clone deep data structures copy-on-write

SYNOPSIS

Top

    use Data::COW;

    my $array = [ 0, 1, 2 ];
    my $copy = make_cow_ref $array;

    push @$array, 3;
    # $copy->[3] is 3
    push @$copy, 4;
    # $array->[4] is not defined (and doesn't even exist)
    # $copy is a real copy now
    push @$array, 5;
    # $copy is unaffected

DESCRIPTION

Top

Data::COW makes copies of data structures copy-on-write, or "lazily". So if you have a data structure that takes up ten megs of memory, it doesn't take ten megs to copy it. Even if you change part of it, Data::COW only copies the parts that need to be copied in order to reflect the change.

Data::COW exports one function: make_cow_ref. This takes a reference and returns a copy-on-write reference to it. If you don't want this in your namespace, and you want to use it as Data::COW::make_cow_ref, use the module like this:

    use Data::COW ();

Data::COW won't be able to copy filehandles or glob references. But how do you change those anyway? It's also probably a bad idea to give it objects that refer to XS internal state without providing a value type interface. Also, don't use stringified references from this data structure: they're different each time you access them!

SEE ALSO

Top

Clone

AUTHOR

Top

Luke Palmer <luke@luqui.org>

COPYRIGHT

Top


Data-COW documentation  | view source Contained in the Data-COW distribution.