Java NIO--data access in buffer

Source: Internet
Author: User

Buffer:

A container for a specific base data type. Defined by the Java.nio package, all buffers are subclasses of the buffer abstract class.
The buffer in Java NIO is primarily used to interact with the NIO channel, where the data is read from the channel into the buffer and written from the buffer to the channel.

Buffer is like an array that can hold multiple data of the same type. Depending on the data type (except for the Boolean), there are the following Buffer common subclasses:
Bytebuffer
Charbuffer
Shortbuffer
Intbuffer
Longbuffer
Floatbuffer
DoubleBuffer
These Buffer classes use similar methods for managing data, except that they manage different types of data. is to obtain a Buffer using the following method
Object:
static Xxxbuffer allocate (int capacity): Creates a Xxxbuffer object with a capacity of capacity

Two core methods for buffer Access data:

Put (): Deposit data into buffer

Get (): Gets the data in the buffer

Four core properties in the buffer:

Capacity: capacity, which represents the maximum amount of data stored in the buffer. Once the declaration cannot be changed.
Limit: Bounds that indicates the size of the data that can be manipulated in the buffer. (data cannot be read or written after limit)
Position: position that represents the position in the buffer where the data is being manipulated.

Mark: Mark, indicating the location of the current position. Can be restored to mark's location via Reset ()

0 <= Mark <= position <= limit <= capacity

Direct buffers vs. non-direct buffers:

Non-direct buffers: allocates buffers through the allocate () method, setting buffers in the JVM's memory
Direct buffer: Allocates a direct buffer through the Allocatedirect () method, establishing the buffer in physical memory. can improve efficiency

Java NIO--data access in buffer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.