Subject: ANNOUNCE: Tie::MmapArray 0.01
From: Andrew Ford <[email-masked]>
Date: 24 Dec 1999 17:50:28 GMT
Newsgroups: comp.lang.perl.announce,comp.lang.perl.modules

I have just uploaded an initial version of Tie::MmapArray to 

	http://www.ford-mason.co.uk/resources/

The module is inspired by Malcolm Beatie's Mmap module, but this one
allows a file to be mapped as an array of integers, f.p. numbers or
fixed-length strings.  The man page is appended.

This is very much a preliminary version (I just wrote it today), but I
hope to have it on CPAN by the new year.

Andrew
-- 
Andrew Ford,  Director       Ford & Mason Ltd           +44 1531 829900 (tel)
[email-masked]      South Wing, Compton House  +44 1531 829901 (fax)
http://www.ford-mason.co.uk  Compton Green, Redmarley   +44 385 258278 (mobile)
http://www.refcards.com      Gloucester, GL19 3JB, UK   

----------------------------------------------------------------------

NAME
    Tie::MmapArray - uses mmap to map in a file as a perl array

SYNOPSIS
        use Tie::MmapArray;

        tie @array, 'Tie::MmapArray', $filename, { eltype => "i",
                                                   nels   => 0,
                                                   mode   => "rw",
                                                   shared => 1,
                                                   offset => 0 };

DESCRIPTION
    The Tie::MmapArray module lets you use mmap to map in a file as a perl
    array rather than reading the file into dynamically allocated memory. It
    depends on your operating system supporting UNIX or POSIX.1b mmap, of
    course.

    The type of array elements is defined byt the *eltype* option, which
    takes a subset of the pack letters:

    i   signed integer (default)

    I   unsigned integer

    c   signed character (one byte integer)

    c   unsigned character (one byte integer)

    s   signed short integer

    S   unsigned short integer

    l   signed long integer

    L   unsigned long integer

    f   float

    d   double

    a*N*
        fixed-length, null-padded ASCII string of length *N*

    A*N*
        fixed-length, space-padded ASCII string of length *N*

    The size of the array is defined by the *nels* option. If this is zero
    then it is calculated as the file size divided by the element size.

    If the file size is smaller than the size required for the requested
    elements then a single zero byte will be written to the final byte of
    the requested size. This seems to prevent the module dying with a
    segmentation or bus error if memory is accessed beyond the end of the
    file and generally results in a file with holes (unallocated blocks).
    Precise details of the behaviour of the module are subject to change.

BUGS, RESTRICTIONS AND FUTURE DIRECTIONS
    As this is version 0.01 of the module there are likely to be many bugs.
    The interface may change as the result of feedback.

    The options *mode*, *shared* and *offset* are not yet used.

    Not all pack letters are implemented yet.

    push, pop, shift, unshift, and splice operations are not yet supported.
    It is debateable whether they should be as they could be very expensive
    if the mmaped file was large (say a Gigabyte or two). Perhaps there
    should be an option to explicitly allow these operations.

    Elements of the array may be allowed to be more complex than just
    scalars. I have in mind something like specifying an array for eltype,
    e.g.:

        tie @array, Tie::MmapArray, $file { eltype => [ field1 => "i",
                                            field2 => "S",
                                            field3 => "a22" ] };

        $array[$recno]->{field3} = "xyzzy...";

    This would allow fixed length records to be manipulated simply. It would
    be feasible to allow a nested structure, but I don't know how complex I
    want this to get.

AUTHOR
    Andrew Ford <[email-masked]>, 20 December 1999.