GCDAsyncSocketPreBuffer Class Reference
Inherits from | NSObject |
---|---|
Declared in | GCDAsyncSocket.m |
Overview
A PreBuffer is used when there is more data available on the socket than is being requested by current read request. In this case we slurp up all data from the socket (to minimize sys calls), and store additional yet unread data in a “prebuffer”.
The prebuffer is entirely drained before we read from the socket again. In other words, a large chunk of data is written is written to the prebuffer. The prebuffer is then drained via a series of one or more reads (for subsequent read request(s)).
A ring buffer was once used for this purpose. But a ring buffer takes up twice as much memory as needed (double the size for mirroring). In fact, it generally takes up more than twice the needed size as everything has to be rounded up to vm_page_size. And since the prebuffer is always completely drained after being written to, a full ring buffer isn’t needed.
The current design is very simple and straight-forward, while also keeping memory requirements lower.