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.

A may be used when moving data between processes within a computer. This is comparable to buffers in telecommunication. Buffers can be implemented in a fixed memory location in hardware—or by using a virtual data buffer in software, pointing at a location in the physical memory. In all cases, the data stored in a data buffer are stored on a physical storage medium. A majority of buffers are implemented in software, which typically use the faster RAM to store temporary data, due to the much faster access time compared with hard disk drives. Buffers are typically used when there is a difference between the rate at which data is received and the rate at which it can be processed, or in the case that these rates are variable, for example in a printer spooler or in online video streaming.


References

7035 questions
89
votes
2 answers

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 data passed in to my cython function from outside…
kynan
  • 13,235
  • 6
  • 79
  • 81
84
votes
5 answers

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
  • 193,756
  • 157
  • 432
  • 708
84
votes
4 answers

Java - Convert int to Byte Array of 4 Bytes?

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) { int length = myBuffer.length; byte[]…
Petey B
  • 11,439
  • 25
  • 81
  • 101
81
votes
4 answers

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 stick to kilobyte-buffers ?
Pygmy
  • 1,856
  • 2
  • 18
  • 13
80
votes
2 answers

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 to byte array? //var data =…
GingerJim
  • 3,737
  • 6
  • 26
  • 36
79
votes
3 answers

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, length); stream.open("test.dat", std::ios::binary |…
Vincent
  • 57,703
  • 61
  • 205
  • 388
78
votes
1 answer

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
  • 3,061
  • 1
  • 29
  • 34
74
votes
4 answers

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 have it buffer all my bytes and return to me a…
jbu
  • 15,831
  • 29
  • 82
  • 105
72
votes
3 answers

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 have a file object that is intended for binary…
jelovirt
  • 5,844
  • 8
  • 38
  • 49
64
votes
14 answers

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
  • 17,128
  • 37
  • 99
  • 136
64
votes
3 answers

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 asking if a fs open is enough or I have to read all…
Leonardo Rossi
  • 2,922
  • 2
  • 20
  • 28
62
votes
6 answers

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 buffer can be used for either reading or writing,…
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
60
votes
4 answers

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 StreamReader.Read(...) pass, I fire off an event which…
AJ.
  • 1,621
  • 1
  • 10
  • 23
60
votes
3 answers

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 in the database log, and I will like to setup…
Henrik Stenbæk
  • 3,982
  • 5
  • 31
  • 33
57
votes
5 answers

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 data seg size (kbytes, -d)…
Gui13
  • 12,993
  • 17
  • 57
  • 104