JAVA SOCKET bytebuffer heap outer memory __java

Source: Internet
Author: User


Generalized heap Memory
when it comes to heap memory, you must think of the memory in the heap, which is what we all touch most, we usually set-xmx in JVM parameters to specify the maximum value of our heap, but this is not the Java heap we understand, The value of the XMX is the largest of both the Cenozoic and the new generation, and we usually add a parameter-xx:maxpermsize in the JVM parameter to specify the maximum of the persistent generation, so the maximum value of the Java heap we know is actually the sum of-XMX and-xx:maxpermsize, Under the generational algorithm, the Cenozoic, the aged and the persistent generation are continuous virtual addresses, because they are distributed together, so the rest can be considered as a heap of memory (generalized), these include the JVM itself in the operation of the allocated memory, Codecache,jni allocated memory, Directbytebuffer allocated memory, and so on

narrowly-defined heap memory
and as Java developers, we often say that the heap of memory overflow, in fact, is the narrow heap of external memory, This mainly refers to the java.nio.DirectByteBuffer in the creation of the time allocated memory, we this article is also mainly to talk about the narrow sense of the heap of memory, because it and we usually encounter problems more closely
JDK/JVM Directbytebuffer implementation
Directbytebuffer is commonly used as a buffer pool in the communication process and is common in NIO frameworks such as Mina,netty
through the above code we know that we can specify the maximum heap memory through-xx:maxdirectmemorysize
Directbytebuffer, when created, uses a unsafe native method to allocate a piece of memory directly to the malloc, which is outside of the heap, and naturally does not have any effect on the GC (except System.GC), Because GC time-consuming operation is mainly the operation of the object within the heap, the operation of this block of memory is also directly through the unsafe native method to operate, the equivalent of Directbytebuffer is just a shell, and we communicate if the data is in the heap, Eventually it will copy a copy to the heap, and then send, so why not directly using the heap of memory. For memory that requires frequent operation, and is only temporary for a while, it is recommended to use the heap of memory, and make a buffer pool, and constantly recycle this memory.
If we use the heap of external memory on a large scale and there is no limit, it will sooner or later cause a memory overflow, after all, the program is running on a resource-constrained machine, because this memory recovery is not directly controlled by

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.