Skip to content

Commit 1713f79

Browse files
authored
Improve IOBuffer docs (#56024)
Based on the discussion in #55978, I have tried to clarify the documentation of `IOBuffer`.
1 parent b3d587d commit 1713f79

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

base/iobuffer.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ It may take optional keyword arguments:
5959
6060
When `data` is not given, the buffer will be both readable and writable by default.
6161
62+
!!! warning "Passing `data` as scratch space to `IOBuffer` with `write=true` may give unexpected behavior"
63+
Once `write` is called on an `IOBuffer`, it is best to consider any
64+
previous references to `data` invalidated; in effect `IOBuffer` "owns"
65+
this data until a call to `take!`. Any indirect mutations to `data`
66+
could lead to undefined behavior by breaking the abstractions expected
67+
by `IOBuffer`. If `write=true` the IOBuffer may store data at any
68+
offset leaving behind arbitrary values at other offsets. If `maxsize > length(data)`,
69+
the IOBuffer might re-allocate the data entirely, which
70+
may or may not be visible in any outstanding bindings to `array`.
6271
# Examples
6372
```jldoctest
6473
julia> io = IOBuffer();

0 commit comments

Comments
 (0)