Skip to content

Commit 6e6b115

Browse files
authored
Docs: link to ShortByteString from ByteString module (#193) (#609)
1 parent 09dc954 commit 6e6b115

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Data/ByteString.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ module Data.ByteString (
4747
ByteString,
4848
StrictByteString,
4949

50+
-- ** Heap fragmentation
51+
-- | With GHC, the 'ByteString' representation uses /pinned memory/,
52+
-- meaning it cannot be moved by GC. While this is ideal for use with
53+
-- the foreign function interface and is usually efficient, this
54+
-- representation may lead to issues with heap fragmentation and wasted
55+
-- space if the program selectively retains a fraction of many small
56+
-- 'ByteString's, keeping them live in memory over long durations.
57+
--
58+
-- While 'ByteString' is indispensable when working with large blobs of
59+
-- data and especially when interfacing with native C libraries, be sure
60+
-- to also check the 'Data.ByteString.Short.ShortByteString' type.
61+
-- As a type backed by /unpinned/ memory, @ShortByteString@ behaves
62+
-- similarly to @Text@ (from the @text@ package) on the heap, completely
63+
-- avoids fragmentation issues, and in many use-cases may better suit
64+
-- your bytestring-storage needs.
65+
5066
-- * Introducing and eliminating 'ByteString's
5167
empty,
5268
singleton,

bytestring.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Description:
3030
.
3131
There is also a 'ShortByteString' type which has a lower memory overhead
3232
and can be converted to or from a 'ByteString'. It is suitable for keeping
33-
many short strings in memory.
33+
many short strings in memory, especially long-term, without incurring any
34+
possible heap fragmentation costs.
3435
.
3536
'ByteString's are not designed for Unicode. For Unicode strings you should
3637
use the 'Text' type from the @text@ package.

0 commit comments

Comments
 (0)