/Haskell 8


Copyright (c) The University of Glasgow 2008
License see libraries/base/LICENSE
Maintainer cvs-ghc@haskell.org
Stability internal
Portability non-portable (GHC Extensions)
Safe Haskell Trustworthy
Language Haskell2010


Buffers used in the IO system

Buffers of any element

data Buffer e Source

A mutable array of bytes that can be passed to foreign functions.

The buffer is represented by a record, where the record contains the raw buffer and the start/end points of the filled portion. The buffer contents itself is mutable, but the rest of the record is immutable. This is a slightly odd mix, but it turns out to be quite practical: by making all the buffer metadata immutable, we can have operations on buffer metadata outside of the IO monad.

The "live" elements of the buffer are those between the bufL and bufR offsets. In an empty buffer, bufL is equal to bufR, but they might not be zero: for example, the buffer might correspond to a memory-mapped file and in which case bufL will point to the next location to be written, which is not necessarily the beginning of the file.




data BufferState Source



type CharBuffer = Buffer Char Source

type CharBufElem = Char Source


newByteBuffer :: Int -> BufferState -> IO (Buffer Word8) Source

newCharBuffer :: Int -> BufferState -> IO CharBuffer Source

newBuffer :: Int -> Int -> BufferState -> IO (Buffer e) Source

emptyBuffer :: RawBuffer e -> Int -> BufferState -> Buffer e Source


bufferRemove :: Int -> Buffer e -> Buffer e Source

bufferAdd :: Int -> Buffer e -> Buffer e Source

slideContents :: Buffer Word8 -> IO (Buffer Word8) Source

slides the contents of the buffer to the beginning

bufferAdjustL :: Int -> Buffer e -> Buffer e Source


isEmptyBuffer :: Buffer e -> Bool Source

isFullBuffer :: Buffer e -> Bool Source

isFullCharBuffer :: Buffer e -> Bool Source

isWriteBuffer :: Buffer e -> Bool Source

bufferElems :: Buffer e -> Int Source

bufferAvailable :: Buffer e -> Int Source

summaryBuffer :: Buffer a -> String Source

Operating on the raw buffer as a Ptr

withBuffer :: Buffer e -> (Ptr e -> IO a) -> IO a Source

withRawBuffer :: RawBuffer e -> (Ptr e -> IO a) -> IO a Source


checkBuffer :: Buffer a -> IO () Source

Raw buffers

type RawBuffer e = ForeignPtr e Source

readWord8Buf :: RawBuffer Word8 -> Int -> IO Word8 Source

writeWord8Buf :: RawBuffer Word8 -> Int -> Word8 -> IO () Source

type RawCharBuffer = RawBuffer CharBufElem Source

peekCharBuf :: RawCharBuffer -> Int -> IO Char Source

readCharBuf :: RawCharBuffer -> Int -> IO (Char, Int) Source

writeCharBuf :: RawCharBuffer -> Int -> Char -> IO Int Source

readCharBufPtr :: Ptr CharBufElem -> Int -> IO (Char, Int) Source

writeCharBufPtr :: Ptr CharBufElem -> Int -> Char -> IO Int Source

charSize :: Int Source

© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).