@@ -1042,14 +1042,6 @@ maximalCopySize = 2 * L.smallChunkSize
10421042------------------------------------------------------------------------------
10431043
10441044-- | A buffer allocation strategy for executing 'Builder's.
1045-
1046- -- The strategy
1047- --
1048- -- > 'AllocationStrategy' firstBufSize bufSize trim
1049- --
1050- -- states that the first buffer is of size @firstBufSize@, all following buffers
1051- -- are of size @bufSize@, and a buffer of size @n@ filled with @k@ bytes should
1052- -- be trimmed iff @trim k n@ is 'True'.
10531045data AllocationStrategy = AllocationStrategy
10541046 (Maybe (Buffer , Int ) -> IO Buffer )
10551047 {- # UNPACK #-} !Int
@@ -1060,11 +1052,20 @@ data AllocationStrategy = AllocationStrategy
10601052{-# INLINE customStrategy #-}
10611053customStrategy
10621054 :: (Maybe (Buffer , Int ) -> IO Buffer )
1063- -- ^ Buffer allocation function. If 'Nothing' is given, then a new first
1064- -- buffer should be allocated. If @'Just' (oldBuf, minSize)@ is given,
1065- -- then a buffer with minimal size @minSize@ must be returned. The
1066- -- strategy may reuse the @oldBuf@, if it can guarantee that this
1067- -- referentially transparent and @oldBuf@ is large enough.
1055+ -- ^ Buffer allocation function.
1056+ --
1057+ -- * If 'Nothing' is given, then a new first buffer should be allocated.
1058+ --
1059+ -- * If @'Just' (oldBuf, minSize)@ is given, then a buffer with minimal
1060+ -- size @minSize@ must be returned. The strategy may reuse @oldBuf@ only if
1061+ -- @oldBuf@ is large enough and the consumer can guarantee that this will
1062+ -- not result in a violation of referential transparency.
1063+ --
1064+ -- /Warning:/ for multithreaded programs, it is generally unsafe to reuse
1065+ -- buffers when using the consumers of 'Builder' in this package. For
1066+ -- example, if 'toLazyByteStringWith' is called with an
1067+ -- 'AllocationStrategy' that reuses buffers, evaluating the result by
1068+ -- multiple threads simultaneously may lead to corrupted output.
10681069 -> Int
10691070 -- ^ Default buffer size.
10701071 -> (Int -> Int -> Bool )
0 commit comments