Luke Palmer > Data-COW-0.02 > Data::COW

Download:
Data-COW-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

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

SYNOPSIS ^

    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 ^

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 ^

Clone

AUTHOR ^

Luke Palmer <luke@luqui.org>

COPYRIGHT ^

    Copyright (C) 2005 by Luke Palmer

    This library is free software; you can redistribute it and/or modify it under
    the same terms as Perl itself, either Perl version 5.8.3 or, at your option,
    any later version of Perl 5 you may have available.
syntax highlighting: