Java官方对于buffer的定义如下:
A container for data of a specific primitive type.
A buffer is a linear, finite sequence of elements of a specific primitive type. Aside from its content, the essential properties of a buffer are its capacity, limit, and position:
A buffer's capacity is the number of elements it contains. The capacity of a buffer is never negative and never changes.
A buffer's limit is the index of the first element that should not be read or written. A buffer's limit is never negative and is never greater than its capacity.
A buffer's position is the index of the next element to be read or written. A buffer's position is never negative and is never greater than its limit.
There is one subclass of this class for each non-boolean primitive type
简单解释三个参数
capacity: 数据容量。即最多能存多少数据。当buffer对象新建的时候就确定了。
position:读写开始的指针位置。
limit: 不允许读写开始的指针位置。
下图展示了一个新建的容积为7的buffer相关参数情况:
其中4个参数有以下关系: 0 <= mark <= position <= limit <= capacity