Buffer
A buffer is a reserved area of memory that temporarily holds data while it travels between two processes, devices or systems running at different speeds. It works like an airlock: the faster side deposits data without waiting, and the slower side drains it at its own pace. Buffering is one of computing's most universal mechanisms — it appears everywhere from disk controllers and network stacks to video players and web servers.
How buffering works
Most buffers operate as FIFO queues — data leaves in the order it arrived. The pattern shows up in a few canonical places:
- disk I/O — operating systems collect small writes in memory and flush them as larger sequential blocks, which is dramatically faster, especially on spinning disks,
- networking — TCP maintains send and receive buffers on both ends; their sizing determines how much bandwidth a connection can actually use on high-latency links (the bandwidth-delay product),
- media streaming — players preload several seconds of audio or video so momentary throughput dips do not interrupt playback,
- web servers — Nginx buffers responses from upstream applications (PHP-FPM, proxied backends), freeing the application worker as soon as the response is generated rather than when the slowest client finishes downloading it.
A buffer is not a cache: buffers smooth data in transit and are read once, while caches keep copies of data for repeated access.
Practical use
Server administrators tune buffers constantly, often without naming them: kernel TCP buffer limits (net.core.rmem_max/wmem_max) govern long-distance transfer speed; Nginx's proxy_buffers and fastcgi_buffers decide whether a response stays in RAM or spills into a temp file; the InnoDB log buffer in MariaDB/MySQL shapes transaction throughput. In application code, output buffering (PHP's ob_start()) lets a script assemble the whole response before any headers are sent.
Buffers also have a security dimension: mishandled bounds lead to buffer overflows, a classic vulnerability class where excess data overwrites adjacent memory and can hand an attacker code execution — the reason modern compilers ship protections like stack canaries and bounds checking.
Powiązane pojęcia
Najczęstsze pytania
What is the difference between a buffer and a cache?
A buffer smooths a flow: data passes through it once, typically in FIFO order, to reconcile speed differences between producer and consumer. A cache stores copies of data expected to be requested again, to avoid recomputing or refetching it. Buffers serve throughput; caches serve repeated access.
