This is G o o g l e's cache of http://home.earthlink.net/~neilbawd/slurp.html.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
To link to or bookmark this page, use the following url: http://www.google.com/search?q=cache:_Wji_gDnixkC:home.earthlink.net/~neilbawd/slurp.html+&hl=en&ie=UTF-8


Google is not affiliated with the authors of this page nor responsible for its content.

SLURP

SLURP

TEXT

Wil Baden 2000-07-26

From JARGON File
slurp
vt. To read a large data file entirely into core before working on it. This may be contrasted with the strategy of reading a small piece at a time, processing it, and then reading the next piece. "This program slurps in a 1K-by-1K matrix and does an FFT."

Two simple ways to slurp a file: GUZZLE, or SLURP and BURP.

GUZZLE              ( file-id -- addr length )
Read all of the file into data space at HERE. Return address and length.
SLURP               ( file-id -- addr length )
Read all of the file into allocated memory. Return address and length. When memory is no longer needed, you must BURP.
BURP                ( -- )
Free the memory allocated by SLURP.

Needed from Tool Belt: REWIND-FILE   FILE-CHECK   MEMORY-CHECK  

Program Text 1
 
: GUZZLE            ( file-id -- addr length )
    >R
    R@ REWIND-FILE FILE-CHECK
    R@ FILE-SIZE FILE-CHECK                 ( file-size 0)
    DROP                                    ( file-size)
    HERE SWAP R> READ-FILE FILE-CHECK       ( length)
    HERE SWAP ;

2VARIABLE Slurp-Address

: SLURP             ( file-id -- addr length )
    >R
    R@ REWIND-FILE FILE-CHECK
    R@ FILE-SIZE FILE-CHECK                 ( file-size 0)
    DROP                                    ( file-size)
    DUP ALLOCATE MEMORY-CHECK               ( file-size addr)
    2DUP Slurp-Address 2!
    SWAP R>                                 ( addr file-size file-id)
    READ-FILE FILE-CHECK                    ( length)
    Slurp-Address @ SWAP                    ( addr length)
    ;

: BURP              ( -- )
    Slurp-Address @ FREE MEMORY-CHECK ;


Go back to Neil Bawd's home page.