Skip to main content

Questions tagged [buffer]

A buffer is an area of memory set aside for temporary storage of data while it is being moved from one place to another. This is typically done to speed up processes with significant latency, such as writing to a disk, printer or other physical device. The output is ready to be sent to the device before the device is ready to accept it, so it is moved to the buffer so that the sending program does not have to continue waiting.

Filter by
Sorted by
Tagged with
697 votes
16 answers
367k views

How can I clear previous output in Terminal in Mac OS X?

I know the clear command that 'clears' the current screen, but it does this just by printing lots of newlines - the cleared contents just get scrolled up. Is there a way to completely wipe all ...
eonil's user avatar
  • 85.2k
589 votes
10 answers
368k views

How do I close a single buffer (out of many) in Vim?

I open several files in Vim by, for example, running vim a/*.php which opens 23 files. I then make my edit and run the following twice :q which closes all my buffers. How can you close only one ...
Léo Léopold Hertz 준영's user avatar
241 votes
9 answers
124k views

What does it mean by buffer?

I see the word "BUFFER" everywhere, but I am unable to grasp what it exactly is. Would anybody please explain what is buffer in layman's language? When is it used? How is it used?
Pratik Deoghare's user avatar
228 votes
14 answers
306k views

Convert a binary NodeJS Buffer to JavaScript ArrayBuffer

How can I convert a NodeJS binary buffer into a JavaScript ArrayBuffer?
Drake Amara's user avatar
  • 3,212
225 votes
5 answers
259k views

What is the use of ByteBuffer in Java? [closed]

What are example applications for a ByteBuffer in Java? Please list any example scenarios where this is used.
Aklin's user avatar
  • 2,651
204 votes
14 answers
257k views

What is the difference between buffer and cache memory in Linux?

To me it's not clear what's the difference between the two Linux memory concepts : buffer and cache. I've read through this post and it seems to me that the difference between them is the expiration ...
James.Xu's user avatar
  • 8,285
198 votes
12 answers
314k views

Save Screen (program) output to a file

I need to save the whole output of Screen to a file to check later all the content. The reason is that I'm dumping a flash memory through a serial port, using Screen to interface with it. I would like ...
Edoardoo's user avatar
  • 2,859
186 votes
3 answers
289k views

Convert a JSON Object to Buffer and Buffer to JSON Object back

I have a JSON object and I'm converting it to a Buffer and doing some process here. Later I want to convert the same buffer data to convert to valid JSON object. I'm working on Node V6.9.1 Below is ...
Prasanth J's user avatar
  • 1,863
180 votes
10 answers
136k views

How do you determine the ideal buffer size when using FileInputStream?

I have a method that creates a MessageDigest (a hash) from a file, and I need to do this to a lot of files (>= 100,000). How big should I make the buffer used to read from the files to maximize ...
ARKBAN's user avatar
  • 3,457
179 votes
9 answers
229k views

Converting a Buffer into a ReadableStream in Node.js

I have a library that takes as input a ReadableStream, but my input is just a base64 format image. I could convert the data I have in a Buffer like so: var img = new Buffer(img_string, 'base64'); But ...
Masiar's user avatar
  • 21.1k
175 votes
7 answers
86k views

Force line-buffering of stdout in a pipeline

Usually, stdout is line-buffered. In other words, as long as your printf argument ends with a newline, you can expect the line to be printed instantly. This does not appear to hold when using a pipe ...
houbysoft's user avatar
  • 33k
160 votes
6 answers
145k views

How large should my recv buffer be when calling recv in the socket library

I have a few questions about the socket library in C. Here is a snippet of code I'll refer to in my questions. char recv_buffer[3000]; recv(socket, recv_buffer, 3000, 0); How do I decide how big to ...
adhanlon's user avatar
  • 6,489
155 votes
8 answers
444k views

Reading and writing binary file

I'm trying to write code to read a binary file into a buffer, then write the buffer to another file. I have the following code, but the buffer only stores a couple of ASCII characters from the first ...
nf313743's user avatar
  • 4,179
153 votes
6 answers
796k views

C char array initialization: what happens if there are less characters in the string literal than the array size?

I'm not sure what will be in the char array after initialization in the following ways. 1.char buf[10] = ""; 2. char buf[10] = " "; 3. char buf[10] = "a"; For case 2, I think buf[0] should be '...
lkkeepmoving's user avatar
  • 2,345
148 votes
8 answers
25k views

How to delete multiple buffers in Vim?

Assuming I have multiple files opened as buffers in Vim. The files have *.cpp, *.h and some are *.xml. I want to close all the XML files with :bd *.xml. However, Vim does not allow this (E93: More ...
Thanh DK's user avatar
  • 4,357
141 votes
10 answers
172k views

Clearing a string buffer/builder after loop

How do you clear the string buffer in Java after a loop so the next iteration uses a clear string buffer?
waterfallrain's user avatar
136 votes
3 answers
78k views

What does flushing the buffer mean?

I am learning C++ and I found something that I can't understand: Output buffers can be explicitly flushed to force the buffer to be written. By default, reading cin flushes cout; cout is also ...
Mohamed Ahmed Nabil's user avatar
133 votes
2 answers
151k views

How to display nodejs raw Buffer data as Hex string

The following code uses SerialPort module to listen to data from a bluetooth connection. I am expecting to see a stream of data in Hexadecimal format printed in console. But the console just shows ...
GingerJim's user avatar
  • 3,867
132 votes
6 answers
78k views

What exactly is the point of memoryview in Python?

Checking the documentation on memoryview: memoryview objects allow Python code to access the internal data of an object that supports the buffer protocol without copying. class memoryview(...
Basel Shishani's user avatar
124 votes
11 answers
33k views

Replace word with contents of paste buffer?

I need to do a bunch of word replacements in a file and want to do it with a vi command, not an EX command such as :%s///g. I know that this is the typical way one replaces the word at the current ...
plong's user avatar
  • 1,753
124 votes
4 answers
40k views

Diff two tabs in Vim

Scenario: I have opened Vim and pasted some text. I open a second tab with :tabe and paste some other text in there. Goal: I would like a third tab with a output equivalent to writing both texts to ...
davetapley's user avatar
  • 17.6k
124 votes
5 answers
27k views

Refresh all files in buffer from disk in vim

The command to refresh a file from version on disk is :e! How can I do the same for all files in the buffer? Background: I need that because I am using git with multiple branches with one vim open ...
odwl's user avatar
  • 2,103
117 votes
20 answers
510k views

How can I clear an input buffer in C?

I have the following program: int main(int argc, char *argv[]) { char ch1, ch2; printf("Input the first character:"); // Line 1 scanf("%c", &ch1); printf("...
ipkiss's user avatar
  • 13.5k
116 votes
5 answers
43k views

Intellij IDEA with ideavim. Cannot copy text from another source

I tried to copy text from IDEA with ideavim plugin, using default vim keybindings (y). But this text isn't copied in global buffer and i can paste it only in IDEA. How can I use copied piece of text ...
Supo's user avatar
  • 1,235
108 votes
4 answers
147k views

How to append binary data to a buffer in node.js

I have a buffer with some binary data: var b = new Buffer ([0x00, 0x01, 0x02]); and I want to append 0x03. How can I append more binary data? I'm searching in the documentation but for appending ...
Gabriel Llamas's user avatar
102 votes
5 answers
81k views

What exactly does "Stream" and "Buffer" mean in Java I/O?

I just learned about input/output using BufferedReader. I wanted to know what exactly are the meanings of the term Stream and Buffer? Also what does this line of code serves us: BufferedReader br=...
user122345656's user avatar
98 votes
16 answers
61k views

How do you prefer to switch between buffers in Vim?

I've tried MiniBufExplorer, but I usually end up with several windows showing it or close it altogether. What I'd like is something like LustyJuggler with incremental search, the way I switch between ...
Alexey Romanov's user avatar
94 votes
9 answers
140k views

Ring Buffer in Java

I have a streaming time series, of which I am interested in keeping the last 4 elements, which means I want to be able to pop the first, and add to the end. Essentially what I need is a ring buffer. ...
Truba's user avatar
  • 941
93 votes
3 answers
50k views

When to use byte array & when byte buffer?

What is the difference between a byte array & byte buffer ? Also, in what situations should one be preferred over the other? [my usecase is for a web application being developed in java].
Rajat Gupta's user avatar
  • 26.3k
91 votes
2 answers
21k views

What is the recommended way of allocating memory for a typed memory view?

The Cython documentation on typed memory views list three ways of assigning to a typed memory view: from a raw C pointer, from a np.ndarray and from a cython.view.array. Assume that I don't have ...
kynan's user avatar
  • 13.5k
89 votes
6 answers
11k views

Why do I need std::get_temporary_buffer?

For what purpose I should use std::get_temporary_buffer? Standard says the following: Obtains a pointer to storage sufficient to store up to n adjacent T objects. I thought that the buffer will be ...
Kirill V. Lyadvinsky's user avatar
86 votes
5 answers
223k views

How to find the socket buffer size of linux

What's the default socket buffer size of linux? Is there any command to see it?
Freewind's user avatar
  • 197k
85 votes
2 answers
88k views

Node.js convert hexadecimal number to byteArray

I want to send a raw buffer using bluetooth connection. The content is a hex number. Currently I split the number manually to an byte array. Is there any function that can help me convert the number ...
GingerJim's user avatar
  • 3,867
84 votes
4 answers
152k views

Java - Convert int to Byte Array of 4 Bytes? [duplicate]

Possible Duplicate: Convert integer into byte array (Java) I need to store the length of a buffer, in a byte array 4 bytes large. Pseudo code: private byte[] convertLengthToByte(byte[] myBuffer)...
Petey B's user avatar
  • 11.5k
84 votes
1 answer
233k views

Flushing buffers in C

Should fflush() not be used to flush a buffer even if it is an output stream? What is it useful for? How do we flush a buffer in general?
mrk's user avatar
  • 3,171
83 votes
4 answers
86k views

C# FileStream : Optimal buffer size for writing large files?

Suppose I'm writing a couple of files to disk, between 2MB and 5GB. What are sensible buffer values for the FileStream ? Is it sensible to work with buffersizes of several megabytes, or should I ...
Pygmy's user avatar
  • 1,896
80 votes
3 answers
37k views

std::fstream buffering vs manual buffering (why 10x gain with manual buffering)?

I have tested two writing configurations: Fstream buffering: // Initialization const unsigned int length = 8192; char buffer[length]; std::ofstream stream; stream.rdbuf()->pubsetbuf(buffer, ...
Vincent's user avatar
  • 59.6k
76 votes
4 answers
72k views

Byte array of unknown length in java

I am constructing an array of bytes in java and I don't know how long the array will be. I want some tool like Java's StringBuffer that you can just call .append(byte b) or .append(byte[] buf) and ...
jbu's user avatar
  • 16.1k
72 votes
3 answers
67k views

Binary buffer in Python

In Python you can use StringIO for a file-like buffer for character data. Memory-mapped file basically does similar thing for binary data, but it requires a file that is used as the basis. Does Python ...
jelovirt's user avatar
  • 5,872
67 votes
3 answers
157k views

Buffer entire file in memory with Node.js

I have a relatively small file (some hundreds of kilobytes) that I want to be in memory for direct access for the entire execution of the code. I don't know exactly the internals of Node.js, so I'm ...
Leonardo Rossi's user avatar
64 votes
14 answers
30k views

Should a buffer of bytes be signed or unsigned char buffer?

Should a buffer of bytes be signed char or unsigned char or simply a char buffer? Any differences between C and C++? Thanks.
jackhab's user avatar
  • 17.5k
62 votes
6 answers
47k views

When to use .NET BufferedStream class?

The MSDN site states: A buffer is a block of bytes in memory used to cache data, thereby reducing the number of calls to the operating system. Buffers improve read and write performance. A ...
Jader Dias's user avatar
  • 89.8k
60 votes
3 answers
28k views

Is there a way to programmably flush the buffer in log4net

I'm using log4net with AdoNetAppender. It's seems that the AdoNetAppender has a Flush method. Is there anyway I can call that from my code? I'm trying to create an admin page to view all the entries ...
Henrik Stenbæk's user avatar
60 votes
4 answers
63k views

File I/O with streams - best memory buffer size

I am writing a small I/O library to assist with a larger (hobby) project. A part of this library performs various functions on a file, which is read / written via the FileStream object. On each ...
AJ.'s user avatar
  • 1,641
59 votes
5 answers
64k views

Pipe buffer size is 4k or 64k?

I read in multiple places that the default buffer size for a pipe is 4kB (for instance, here), and my ulimit -a tends to confirm that statement: $ ulimit -a core file size (blocks, -c) 0 ...
Gui13's user avatar
  • 13.4k
58 votes
5 answers
32k views

Why doesn't Ruby have a real StringBuffer or StringIO?

I recently read a nice post on using StringIO in Ruby. What the author doesn't mention, though, is that StringIO is just an "I." There's no "O." You can't do this, for example: s = StringIO.new s &...
James A. Rosen's user avatar
55 votes
6 answers
25k views

How to redirect ex command output into current buffer or file?

How can I redirect or pipe the output of an ex command into my current buffer or a file? For example, I want to read the contents of all the registers into the current buffer, which in ex mode is ...
Aman Jain's user avatar
  • 11.2k
52 votes
3 answers
9k views

How can I save my mini-buffer history in Emacs?

I'd like to save, for instance, my find-file and Meta-X history in Emacs' mini-buffer so I can recall commands later in a different session.
Jonathon Watney's user avatar
50 votes
1 answer
68k views

How to know actual size of byte buffer`s content in nodejs?

I get files as byte buffers and cannot use fs.stat() method. So I am try to use buf.length but this length refers to the amount of memory allocated for the buffer object and not actually the content ...
lor1an's user avatar
  • 704
50 votes
2 answers
28k views

Use of Vertex Array Objects and Vertex Buffer Objects

I am trying to understand these two, how to use them and how they are related. Let's say I want to create a simple terrain and a textured cube. For both objects I have the array of triangles vertices ...
ali's user avatar
  • 11k

1
2 3 4 5
143