NOTE

Buffer

Basic Buffer usage and the meanings of capacity, position, and limit.

JavaCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

Basic Usage

Write data into the Buffer.

Call flip().

Read data from the Buffer.

Call clear() or compact().

Principle

There are three properties:

  • capacity
  • position
  • limit

The meanings of position and limit depend on whether the Buffer is in read mode or write mode. The meaning of capacity is always the same regardless of the Buffer’s mode.

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub