• Herbert Valerio Riedel's avatar
    Implement {resize,shrink}MutableByteArray# primops · 246436f1
    Herbert Valerio Riedel authored
    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 #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
    246436f1
Cmm.h 35.1 KB