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
30
votes
4 answers

How to convert buffer to stream in Nodejs

I confront with a problem about converting buffer into stream in Nodejs.Here is the code: var fs = require('fs'); var b = Buffer([80,80,80,80]); var readStream = fs.createReadStream({path:b}); The code raise an exception: TypeError: path must be a…
zhangjpn
  • 355
  • 1
  • 3
  • 6
30
votes
7 answers

CharBuffer vs. char[]

Is there any reason to prefer a CharBuffer to a char[] in the following: CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE); while( in.read(buf) >= 0 ) { out.append( buf.flip() ); buf.clear(); } vs. char[] buf = new…
Chris Conway
  • 55,321
  • 43
  • 129
  • 155
29
votes
4 answers

How can I store an integer in a nodejs Buffer?

The nodejs Buffer is pretty swell. However, it seems to be geared towards storing strings. The constructors either take a string, an array of bytes, or a size of bytes to allocate. I am using version 0.4.12 of Node.js, and I want to store an integer…
Jamison Dance
  • 19,896
  • 25
  • 97
  • 99
29
votes
2 answers

TypeError: coercing to Unicode: need string or buffer, int found

I have 2 APIs. I am fetching data from them. I want to assign particular code parts to string so that life became easier while coding. Here is the code: import urllib2 import json urlIncomeStatement = 'http://dev.c0l.in:8888' apiIncomeStatement =…
Marks Gniteckis
  • 473
  • 1
  • 6
  • 18
29
votes
8 answers

Correct way to read a text file into a buffer in C?

I'm dealing with small text files that i want to read into a buffer while i process them, so i've come up with the following code: ... char source[1000000]; FILE *fp = fopen("TheFile.txt", "r"); if(fp != NULL) { while((symbol = getc(fp)) !=…
Gary Willoughby
  • 50,926
  • 41
  • 133
  • 199
29
votes
2 answers

When to use Array, Buffer or direct Buffer

Question While writing a Matrix class for use with OpenGL libraries, I came across the question of whether to use Java arrays or a Buffer strategy to store the data (JOGL offers direct-buffer copy for Matrix operations). To analyze this, I wrote a…
TwoThe
  • 13,879
  • 6
  • 30
  • 54
28
votes
4 answers

Printf a buffer of char with length in C

I have a buffer which I receive through a serial port. When I receive a certain character, I know a full line has arrived, and I want to print it with printf method. But each line has a different length value, and when I just go with: printf("%s",…
Roman Rdgz
  • 12,836
  • 41
  • 131
  • 207
28
votes
10 answers

What happens if I write less than 12 bytes to a 12 byte buffer?

Understandably, going over a buffer errors out (or creates an overflow), but what happens if there are less than 12 bytes used in a 12 byte buffer? Is it possible or does the empty trailing always fill with 0s? Orthogonal question that may help:…
hexadec0079
  • 323
  • 3
  • 5
28
votes
1 answer

Specifying UDP receive buffer size at runtime in Linux

In Linux, one can specify the system's default receive buffer size for network packets, say UDP, using the following commands: sysctl -w net.core.rmem_max= sysctl -w net.core.rmem_default= But I wonder, is it possible for an…
Mαzen
  • 535
  • 2
  • 7
  • 14
28
votes
2 answers

what happens when I write data to a blocking socket, faster than the other side reads?

suppose I write data really fast [I have all the data in memory] to a blocking socket. further suppose the other side will read data very slow [like sleep 1 second between each read]. what is the expected behavior on the writing side in this case?…
Aviad Rozenhek
  • 2,259
  • 3
  • 21
  • 42
27
votes
2 answers

How can I make reverse scanning of a binary file faster?

I have a binary file specification that describes a packetized data structure. Each data packet has a two-byte sync pattern, so scanning for the beginning of a packet is possible, using a BinaryReader and FileStream…
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
27
votes
6 answers

Does reactive extensions support rolling buffers?

I'm using reactive extensions to collate data into buffers of 100ms: this.subscription = this.dataService .Where(x => !string.Equals("FOO", x.Key.Source)) .Buffer(TimeSpan.FromMilliseconds(100)) .ObserveOn(this.dispatcherService) …
Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
27
votes
5 answers

Copy data from fstream to stringstream with no buffer?

Is there anyway I can transfer data from an fstream (a file) to a stringstream (a stream in the memory)? Currently, I'm using a buffer, but this requires double the memory, because you need to copy the data to a buffer, then copy the buffer to the…
Brad
  • 10,015
  • 17
  • 54
  • 77
27
votes
1 answer

Why is modifying a string through a retrieved pointer to its data not allowed?

In C++11, the characters of a std::string have to be stored contiguously, as § 21.4.1/5 points out: The char-like objects in a basic_string object shall be stored contiguously. That is, for any basic_string object s, the identity &*(s.begin() + n)…
chris
  • 60,560
  • 13
  • 143
  • 205
27
votes
3 answers

Android MediaPlayer takes long time to prepare and buffer

My application takes a long time to prepare and buffer an audio stream. I have read this question Why does it take so long for Android's MediaPlayer to prepare some live streams for playback?, however it just says people have experienced this issue,…
SteveEdson
  • 2,485
  • 2
  • 28
  • 46