Java NiO Learning Summary (i)

Source: Internet
Author: User

When learning the operating system, we all know the role of DMA (direct memory read), the previous I/O is called a system interrupt to tell the CPU I moved to 4k of data block for the CPU to calculate,
In this cycle, the CPU interacts with the I/O more often, and the DMA is transferred to the CPU using chunks of data (much larger than 4k).
So before the DMA transfer task is complete, the CPU is having a lot of events to be merry.
Let's look at the Java Virtual machine, the traditional Java I/O class like to read small chunks of data, this time to obtain the DMA provided by the large buffer, the Java stream data class will be
He tore up a lot of small pieces. This greatly reduces efficiency, so Java launches the NIO (Bytebuffer object).
Traditional I/O models can actually move large amounts of data, randomaccessfile using the array-based read () and write () methods, which are fairly close to system calls, but
He must keep at least one copy of the buffer.

/ o

User space is what we often say (non-privileged areas, can not directly invoke system rights such as reading hardware devices), the kernel space is the pipe (privileged area, for the operating system
Licensee
Why can't I read data directly from disk to user space?
Because a block of data on a disk is a fixed size and the user process is requesting a block of arbitrary size or even a boundary misalignment, a third party (kernel) is required to
The data is divided, combined, and forwarded.
Basic concepts
Go to NiO: buffers (buffer)
The following diagram describes the buffer family members

Properties of the buffer: capacity, upper bound, position, tag.
Capacity (capcapacity): The maximum number of data that a buffer can hold.
Upper bound (Limit): The first element in a buffer that cannot read/write. That is, the current buffer has the number of elements.
Location (Position):

Java NiO Learning Summary (i)

Related Article

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.