Buffer.truncate(size)
See original GitHub issueI found myself in a situation today where it was more efficient to write extra data (in the form of SegmentedByteStrings) to a buffer and truncate the buffer. Currently, I’m doing it this way:
long oldSize = sink.size();
long toWrite = Math.min(byteCount, SEGMENT_SIZE);
// ... maybe other writes
sink.write(segmentTemplate); // might overfill the buffer
sink.readAndWriteUnsafe(cursor);
try {
cursor.resizeBuffer(oldSize + toWrite);
} finally {
cursor.close();
}
This would also be alleviated if there was better handling of ByteStrings substrings. Either make creating substrings of a SegementedByteString share the underlying segments or add a BufferedSink.write method which allows for a begin and end index when writing a ByteString. Probably all good things regardless?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Truncate buffer from front - Stack Overflow
Buffer object has a Truncate(n int) method to discard all but the first n bytes. I'd need the exact inverse of that -...
Read more >TRUNC—Truncate buffer (QSAM output—fixed or ... - IBM
On input, the system uses the block size specified in DCBBLKSI for reading the PDSE. When a variable-length spanned record is truncated and...
Read more >Truncating buffers could come in handy · Issue #6975 - GitHub
Buffer.truncate would be trivial to implement in O(1) with access to the ... if Buffer.length buf > max_len then Buffer.truncate buf max_len.
Read more >How we can truncate a file at a given size using Python?
The truncate() function has no return value. To examine the file's increased size after appropriately applying truncate(), open the file's ...
Read more >How do I automatically truncate a growing buffer?
By default, the buffer will be truncated at 1024 lines. To change it to 1000 you will need to change the variable comint-buffer-maximum-size...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As a general rule I prefer all Buffer changes to be either reading from the front or writing to the end. You can cheat to truncate like so:
I wonder which of the two variants will perform better. One of ’em might share segments better than the other.
No worries, I sort of jumped topics pretty quick there. Closing as the original request is not going to be implemented.