Comments (6)
Bytes always stores all of its data as a single contiguous slice. So, are you asking for a way to easily allocate a new buffer and copy all the bytes into it?
Or do you mean combine without allocation? In that case, perhaps you'd want to reach for an impl Buf
, which doesn't promise to be a single contiguous slice. A simple one exists within the crate, Chain
. But new ones can be implemented too.
If you mean a 3rd option of combining specifically in Bytes
, but without an allocation, I don't see how that could be possible.
from bytes.
@seanmonstar I meant combine without allocation, so I think Chain is what I'm looking for!
However, re: the 3rd option,
Say I have a big BytesMut that I am splitting off into smaller blocks. At some point I want to grab a range that might span over multiple blocks.
Now, say I have those blocks, I can order them, so technically underneath the hood they are all part of the same contiguous chunk. In this case, would it be feasible to create a Bytes by using the pointer information from the first and last block?
from bytes.
It might be possible, but not with the methods exposed today. And I wouldn't recommend depending on the internal details to do it externally.
from bytes.
The bytes crate has an unsplit
method.
I don't think we can otherwise support this, so I will close the feature request.
from bytes.
@seanmonstar definitely, I wouldn't try to hack that together externally.
But I was thinking about how with try_reclaim
and unsplit
, the original BytesMut is able to know that the reclaimed memory has no more references, so in the other direction would you be able to create a Bytes from the allocated memory space.
(@Darksonn I was hoping to just articulate the idea a bit more, so sorry to comment on a closed issue)
Basically, if I had an imaginary api like:
impl BytesMut {
fn view_allocated(&self, offset: usize, len: usize) -> Option<Bytes>;
}
Would the owning BytesMut
be able to know that all bytes along that range were frozen, such that returning a Bytes
for that range would be safe.
from bytes.
No, BytesMut
does not know which regions are frozen and which are part of a BytesMut
.
from bytes.
Related Issues (20)
- Enable shrinking of allocations
- Contradictory allocation behaviour compared to documentation HOT 9
- Confusing documentation around `Arc<[u8]>` compatibility HOT 1
- Should clone benchmark use use `test::blackbox`? HOT 1
- Explicitly guarantee `Bytes` to be immutable HOT 2
- Expose UTF-8 validated string type HOT 3
- Buf::chunks_vectored() is wrong if chunk() isn't the whole buf HOT 3
- Feature request: fallible version of `BytesMut::unsplit` (i.e. make `BytesMut::try_unsplit` public) HOT 2
- Test for unknown --cfg flags in ci
- Splice for BytesMut HOT 2
- Consider replacing Bytes::make_mut by impl From<Bytes> for BytesMut HOT 5
- Is the conversion from bytes to Vec<u8> O(1) HOT 5
- Feature request: implement `From<Cow<'static, [u8]>>` for `Bytes`
- BytesMut::zeroed doc header improvement HOT 3
- Docs: `Buf::chunk` should have more restrictions. HOT 2
- 1.6.0 yanked? HOT 12
- `impl FromIterator for BytesMut` exposes implementation details HOT 7
- BytesMut::advance no longer advances cursor HOT 4
- `Buf::get_int()` implementation for `Bytes` returns positive number instead of negative when `nbytes` < 8. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bytes.