Class Buffer
A buffer is a list of elements of a specific primitive type.
A buffer can be described by the following properties:
- Capacity: The number of elements a buffer can hold. Capacity may not be negative and never changes.
- Position: A cursor of this buffer. Elements are read or written at the position if you do not specify an index explicitly. Position may not be negative and not greater than the limit.
-
Limit:
Controls the scope of accessible elements. You can only read or
write elements from index zero to
limit - 1
. Accessing elements out of the scope will cause an exception. Limit may not be negative and not greater than capacity. - Mark: Used to remember the current position, so that you can reset the position later. Mark may not be negative and no greater than position.
- A buffer can be read-only or read-write. Trying to modify the elements of a read-only buffer will cause a ReadOnlyBufferException, while changing the position, limit and mark of a read-only buffer is OK.
- A buffer can be direct or indirect. A direct buffer will try its best to take advantage of native memory APIs and it may not stay in the heap, thus it is not affected by garbage collection.
Buffers are not thread-safe. If concurrent access to a buffer instance is required, then the callers are responsible to take care of the synchronization issues.
Inherited Members
Namespace: Lucene.Net.Support.IO
Assembly: Lucene.Net.dll
Syntax
public abstract class Buffer
Properties
| Improve this Doc View SourceCapacity
Returns the capacity of this buffer.
Declaration
public int Capacity { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
HasRemaining
Indicates if there are elements remaining in this buffer, that is if
position < limit
.
Declaration
public bool HasRemaining { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsReadOnly
Indicates whether this buffer is read-only.
Declaration
public abstract bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Limit
Gets or Sets the limit of this buffer.
Declaration
public int Limit { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Position
Returns the position of this buffer.
Declaration
public int Position { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remaining
Returns the number of remaining elements in this buffer, that is
limit - position
.
Declaration
public int Remaining { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceClear()
Clears this buffer.
While the content of this buffer is not changed, the following internal changes take place: the current position is reset back to the start of the buffer, the value of the buffer limit is made equal to the capacity and mark is cleared.
Declaration
public Buffer Clear()
Returns
Type | Description |
---|---|
Buffer | This buffer |
Flip()
Flips this buffer.
The limit is set to the current position, then the position is set to zero, and the mark is cleared.
The content of this buffer is not changed.
Declaration
public Buffer Flip()
Returns
Type | Description |
---|---|
Buffer | This buffer |
Mark()
Marks the current position, so that the position may return to this point later by calling Reset().
Declaration
public Buffer Mark()
Returns
Type | Description |
---|---|
Buffer | This buffer |
Reset()
Resets the position of this buffer to the Lucene.Net.Support.IO.Buffer.mark.
Declaration
public Buffer Reset()
Returns
Type | Description |
---|---|
Buffer | This buffer |
Exceptions
Type | Condition |
---|---|
InvalidMarkException | If the mark has not been set |
Rewind()
Rewinds this buffer.
The position is set to zero, and the mark is cleared. The content of this] buffer is not changed.
Declaration
public Buffer Rewind()
Returns
Type | Description |
---|---|
Buffer | This buffer |
SetLimit(Int32)
Sets the limit of this buffer.
If the current position in the buffer is in excess of
newLimit
then, on returning from this call, it will have
been adjusted to be equivalent to newLimit
. If the mark
is set and is greater than the new limit, then it is cleared.
Declaration
public Buffer SetLimit(int newLimit)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | newLimit | The new limit value; must be non-negative and no larger than this buffer's capacity |
Returns
Type | Description |
---|---|
Buffer | This buffer |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | If |
SetPosition(Int32)
Sets the position of this buffer.
If the mark is set and it is greater than the new position, then it is cleared.
Declaration
public Buffer SetPosition(int newPosition)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | newPosition | The new position, must be not negative and not greater than limit. |
Returns
Type | Description |
---|---|
Buffer | This buffer |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | If |