Implement {resize,shrink}MutableByteArray# primops

Authored by hvr on Aug 16 2014, 2:49 AM.

Description

Implement {resize,shrink}MutableByteArray# primops

The two new primops with the type-signatures

resizeMutableByteArray# :: MutableByteArray# s -> Int#
                        -> State# s -> (# State# s, MutableByteArray# s #)

shrinkMutableByteArray# :: MutableByteArray# s -> Int#
                        -> State# s -> State# s

allow to resize MutableByteArray#s in-place (when possible), and are useful
for algorithms where memory is temporarily over-allocated. The motivating
use-case is for implementing integer backends, where the final target size of
the result is either N or N+1, and only known after the operation has been
performed.

A future commit will implement a stateful variant of the
sizeofMutableByteArray# operation (see Trac #9447 for details), since now the
size of a MutableByteArray# may change over its lifetime (i.e before
it gets frozen or GCed).

Test Plan: ./validate --slow

Reviewers: ezyang, austin, simonmar

Reviewed By: austin, simonmar

Differential Revision: https://phabricator.haskell.org/D133

Details

Committed
hvrAug 16 2014, 9:01 AM
Pushed
bgamariAug 25 2016, 1:39 PM
Reviewer
austin
Differential Revision
D133: Add new primops {resize,shrink}MutableByteArray#
Parents
rGHCDIFFd39c434a9518: Make configure's sed(1) expression for GHC_LDFLAGS more BSD-friendly.
Branches
Unknown
Tags
Unknown