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
12
votes
2 answers

What is the difference between memory, buffer and stack?

While learning C programming only the memory is mentioned, but in practice it seems that there is more; the buffer and stack words are also used. What is the difference between these terms? Why are they relevant? Please, I need a detailed answer.…
rullof
  • 7,124
  • 6
  • 27
  • 36
12
votes
2 answers

Causing a buffer Overflow with fgets

I'm experimenting with buffer overflows and try to overwrite the return address of the stack with a certain input of fgets This is the code: void foo() { fprintf(stderr, "You did it.\n"); } void bar() { char buf[20]; puts("Input:"); …
arnoapp
  • 2,416
  • 4
  • 38
  • 70
12
votes
3 answers

Is there a buffer size attached to stdout?

I am trying to find some information on data limits related to stdout on Windows. I can't seem to find the information on MSDN. Is there a limit to how much data can be written to stdout? If so, what happens if the limit is reached? Is the data…
jameswelle
  • 1,367
  • 1
  • 15
  • 26
12
votes
3 answers

UnsupportedOperationException with converting byte[] to float[]

I'm trying to convert a byte[] to a float[] by putting the byte[] in a ByteBuffer, converting this to a FloatBuffer (.asFloatBuffer), and then converting this to an array. private static float[] toFloatArray(byte[] bytes) { ByteBuffer buffer =…
user717572
  • 3,626
  • 7
  • 35
  • 60
12
votes
1 answer

PushbackInputStream: Push back buffer is full

Why I am getting the following exception: Exception in thread "main" java.io.IOException: Push back buffer is full at java.io.PushbackInputStream.unread(PushbackInputStream.java:232) at…
alien01
  • 1,334
  • 2
  • 14
  • 31
12
votes
3 answers

Implementing a fixed-size log file, or a circular buffer on disk

I checked this question, but it's not what I'm looking for. I'm trying to figure out how to cap a log file's size (say, 10MB), and as soon as it's hit, either: start writing to the beginning, rather than appending, or keep appending, but delete…
warren
  • 32,620
  • 21
  • 85
  • 124
12
votes
3 answers

How to play MP3 sound from buffer (ByteArray/Stream) in ActionScript 3?

So.. I have a buffer with MP3 data (If I would save this buffer and call it buffer.mp3 it would play, but in this situation I should not save it to file system). I have to play it, but I can not, what shall I do? I tried the next code to play that…
Rella
  • 65,003
  • 109
  • 363
  • 636
12
votes
5 answers

Threadsafe FIFO Queue/Buffer

I need to implement a sort of task buffer. Basic requirements are: Process tasks in a single background thread Receive tasks from multiple threads Process ALL received tasks i.e. make sure buffer is drained of buffered tasks after a stop signal is…
user1300560
  • 255
  • 1
  • 3
  • 12
12
votes
5 answers

Why getline() skipping input, even after cin.clear()?

So I have a function that keeps skipping over the first getline and straight to the second one. I tried to clear the buffer but still no luck, what's going on? void getData(char* strA, char* strB) { cout << "Enter String 1: "; //…
Derp
  • 921
  • 3
  • 14
  • 22
12
votes
5 answers

How to determine the size of an allocated C buffer?

I have a buffer and want to do a test to see if the buffer has sufficient capacity I.e. find number of elements I can add to the buffer. char *buffer = (char *)malloc(sizeof(char) * 10); Doing a int numElements = sizeof(buffer); does not return…
godzilla
  • 3,005
  • 7
  • 44
  • 60
12
votes
2 answers

PHP ob_start() and ob_start('ob_gzhandler')

What is the difference between using ob_start() and ob_start('ob_gzhandler') ? How does it affect the page speed ?
Sithu
  • 4,752
  • 9
  • 64
  • 110
12
votes
2 answers

setvbuf not able to make stdin unbuffered

My main intention was to make getchar return as soon as it gets a character instead of waiting for the ENTER key. I tried this int main() { setvbuf(stdin,NULL,_IONBF,0); getchar(); return 0; } Comparing this with the prototype of…
Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125
11
votes
1 answer

Read into a bytearray at an offset?

How can I use the readinto() method call to an offset inside a bytearray, in the same way that struct.unpack_from works?
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
11
votes
3 answers

Node.js : difference between Buffer.slice and Buffer.subarray

I have a look at the Node.js Buffer documentation and I don't understand the difference between Buffer.slice and Buffer.subarray. Both point to "the same memory as the original". But no one seems not to be the alias of the other (it seems to be said…
doom
  • 3,276
  • 4
  • 30
  • 41
11
votes
4 answers

Dynamically sized boost::asio::buffer

I'm reading from a boost::asio::ip::udp::socket like this: using boost::asio::ip::udp; // ... char recv_buf[128]; udp::endpoint sender_endpoint; size_t len = socket.receive_from(boost::asio::buffer(recv_buf), sender_endpoint); Now, this works…
orlp
  • 112,504
  • 36
  • 218
  • 315