Reputation: 2127
Suppose I have two buffers:
uint8_t* buf1[100];
uint8_t* buf2[10];
uint8_t* buf3[90];
Where buf1
is full of data and I need to pass 10 bytes of this data to buf2
and the rest to buf3
. Is there a way to do this without copying?
If not, is there a high level library (like std::vector
) in which splicing is possible without copying?
Upvotes: 2
Views: 520
Reputation: 20579
No, this is not possible. The three buffers are distinct objects with different addresses. Therefore, some form of copying is necessary.
You can use a span
:
span<uint8_t*, 10> buf2(buf1, 10);
span<uint8_t*, 90> buf3(buf1 + 10, 90);
span
is not in the standard library as of C++17, but it is available in the GSL. See What is a "span" and when should I use one?.
Upvotes: 6