File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments