Skip to content

Commit

Permalink
Docs: link to ShortByteString from ByteString module (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulidtko committed Aug 18, 2023
1 parent e8a9b52 commit b2b36b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Data/ByteString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ module Data.ByteString (
ByteString,
StrictByteString,

-- ** Heap fragmentation
-- | With GHC, the 'ByteString' representation uses /pinned memory/,
-- meaning it cannot be moved by GC. While this is ideal for use with
-- the foreign function interface and is usually efficient,
-- this representation may lead to issues with heap fragmentation
-- and wasted space if the program retains many small 'ByteString's
-- live in memory over long durations or (de)allocates at high rates.
--
-- While 'ByteString' is indispensable when working with large blobs of
-- data and especially when interfacing with native C libraries, be sure
-- to also check the 'Data.ByteString.Short.ShortByteString' type.
-- As a type backed by /unpinned/ memory, @ShortByteString@ is more
-- similar to @Text@ on the heap, completely avoids fragmentation issues,
-- and in many use-cases may better suit your bytestring-storage needs.

-- * Introducing and eliminating 'ByteString's
empty,
singleton,
Expand Down
3 changes: 2 additions & 1 deletion bytestring.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Description:
.
There is also a 'ShortByteString' type which has a lower memory overhead
and can be converted to or from a 'ByteString'. It is suitable for keeping
many short strings in memory.
many short strings in memory, especially long-term, without incurring any
possible heap fragmentation costs.
.
'ByteString's are not designed for Unicode. For Unicode strings you should
use the 'Text' type from the @text@ package.
Expand Down

0 comments on commit b2b36b5

Please sign in to comment.