Shallow Size Vs Retained Size
Sizes, its plasticity, and its relative density or stiffness. Classification by Distribution of Grain Sizes. While an experienced geotechnical engineer can visually examine a soil sample and estimate its grain size distribution, a more accurate determination can be made by performing a sieve analysis.
- Sep 02, 2017 Shallow size – size of the object itself including only references to other objects, without objects which are referenced. Retained size – size of the object including references to other objects.
- Shallow & Retained Heap Size Calculation - By gceasy I have shared many tips related to heap dump analysis in the past. To continue the treasure of performance engineering related to heap dump, today I am sharing an article which described the calculation of shallow and retained heap size in a very simple way along with the examples (especially.
In this article, we look at the three different sizes that objects can be in a heap analysis, and what this means for your performance.
Join the DZone community and get the full member experience.
Join For FreeIf you ever worked with heap analysis, you might have encountered terms such as shallow, retained, and deep size of an object. It doesn’t really matter if we’re talking about analyzing a JVM heap dump with VisualVM or a JavaScript heap snapshot with Chrome DevTools – the terms are the same. The difference between shallow, retained, and deep size is rather straightforward and it can be easily depicted with the following images:
Shallow size – size of the object itself including only references to other objects, without objects which are referenced.
Retained size – size of the object including references to other objects and objects which are referenced, but are not shared with any other objects. In other words, the retained memory of an object is the amount of memory that would be freed if the object A was eligible to be collected by GC. Memory of the object E couldn’t be freed because it is also an instance variable of object B.
Deep size – size of the object including references to other objects and objects which are referenced, even if they are shared with other objects.
Published at DZone with permission of Grzegorz Mirek, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Popular on DZone
VS stack retention size _ deep-in-depth shallow size end (Endianness)
tags: VS stack keeps the size
really don't think about it?4103 words in the full text, is expected to read time 12 minutes
Before entering this topic, I will tell the gang first:
'Endian' The word earliest appeared in Jonathan Swift, in the novel, small people for boiled eggs from big end (Little-End) Stripping and arguing, the two sides of the debate are called 'big end' and 'small end'.
'The book is described in 1726, the two major powers of Lilliput and BLEFUSCU have been suffering in the past 36 months. The war begins because of the following reasons: We all believe that before eating eggs, the original method is to break the eggs. One end, but the grandfather of the emperor today eats eggs, and I happen to break a finger when playing eggs in ancient times. So his father, the emperor at the time, gave it, ordered all the ministers to eat eggs to break the egg. The smaller end, the violation is heavy. The people are extremely anti-sense of this order. History tells us that there have been 6 rebels, one of which emperors sent life, and another lost the throne. These rebels are mostly It is incited by the King of Blefuscu. After the rebellion calm, the people in exile always flee into the empire to seek to avoid refuge. It is estimated that there are 11,000 people in a few times, and they will not be able to break the egg. For this dispute, there have been several hundred works, but the big-ended books have been banned. The law also stipulates that anyone should not be official. '-Wiki
After hundreds of years, how to eat eggs is not important, but there is another dispute in the computer field: memory size. Want to fully understand the size of the size, first understand a concept called byte (endianness), we extracted the definition of endianness on Wiki:
In computing, endianness is the ordering or sequencing of bytes of a word of digital data in computer memory storage or during transmission.
WikipediaDue to the computer system, the data stores in bytes, such as the int occupy 4 bytes in the C language, the word sequence is described in the four bytes stored in the memory. After understanding this concept, we will enter the memory of the memory to see what is the size of the size ~
1
What is the size of the size?
In the computer, the byte sequence is primarily divided into large end storage (Little-endian). Similarly, in order to deepen, we extracted the definition of these two concepts in Wiki:
·A big-endian system stores the most significant byte(MSB) of a word at the smallest memory address and the least significant byte(LSB) at the largest.
·A little-endian system, in contrast, stores the least significant byte(LSB) at the smallest address.
WikipediaFor shallow, you can first look at an example, suppose we define a unsigned int type data DATA:
The unsigned int type takes four bytes, then in the memory, the spatial allocation of Big-endian and Little-Endian is:
It can be seen that the BIG-Endian mode is stored in the low address, and the Little-Endian mode is to store the low storage of the data in a high address, and the rule is so simple. The following figure can help you more image:
Image Source: https: //thebittheories.com/little-endian-vs-big-endian-b4046c63e1f2
NOTICE: The size of the size is only valid for the byte of the data type itself, and the storage of the array does not work.
2
Is the size of the CPU or OS?
The size of the size is defined by the data in the underlying memory space, so it is definitely related to the CPU.
For example, if the CPU only supports the small-end mode and the OS is not to store data according to the big end mode (this is certainly crazy), the size of the size will cost a certain resource. The efficiency will be reduced. Therefore, the current OS is compliant with the mode supported by the CPU to store data. However, the size of the size cannot be said that the OS has no relationship. For example, the processor of the ARM kernel can support the size of two modes at the same time. At this time, the OS can select the appropriate storage method according to the operating environment. . The answer to this question is: the size of the size is the platform-related (depending on the CPU + OS operating environment).Support Big-Endian CPU: IBM, Freescale Coldfire, AVR32, OpenRISC
Support Little-Endian CPU: X86, AMD64 / X86-64, Qualcomm HEXAGON
At the same time, BIG-LITTLE-Endian's CPU: PowerPC, MIPS, ARM AARCH64, RISC-V
3
Why do I need to specify the size of the size?
Question out: This question is like asks why the operating system is also divided into Windows, Mac OS and Linux, everyone uses Linux not good? (Who doesn't want to have a hundred years of mountain rivers, but the minister is not there, then you can only play with a rule.
Let's take a look at what features of the size of the size:
big-endian:
It is more likely to achieve comparison and division operations for variables of the same length
Handling of network communication packets, more friendly (such as TCP / IP)
The judgment of the symbol is more convenient
little-endian:
Easy to achieve, minus, and multiply
Reduce the number of data for data at a specific occasion
Handling for low data is more friendly
It seems that there is a thousand autumn, but in fact, it is actually the reason for differentiation: Early computers when communicating network communication, due to the high performance, the data buffer is not large, using large-end mode to make the computer receive When the data packet header can analyze the nature, length and other information of the data faster, and the buffer pool can be left to subsequent data fill in the earlier analysis, so many CPUs are used in large-end models. And the communication protocol adopts large-end model habits to now, causing almost all of the communication protocols that are now larger end mode.
Later, Intel also designed a small-end mode CPU as X86, because the small-end mode adder is easier to implement, and can simplify the design of the hardware circuit in the ALU unit, and reduce costs can enter the majority of consumer groups (after all in that year. A transistor can save a lot of money).
Later, with the birth of Moore's law and the development of integrated circuits, the current computer performance is already early index, so the size of the size is not so important in today's computer, but the manufacturer still according to the previous design. Experience and application scenarios to select size-ended CPUs, such as MCUs, or small-end CPUs to reduce overall costs (saying that the bottom is the inevitable event in the historical process. If you are unified, I am unified, my article is still written? )
4
What is the size of the size?
There are many situations involving the size of the size, and three more typical examples are given here:
Network communication
The current network communication protocol is basically larger end mode. It is well known that the data is transmitted in bytes in the network or air, so the sender is packaged in accordance with the large end rules when the data is packaged. The party must also be subjected to data reorganization in terms of large end rules. For example, in C language uses Union to complete multi-byte data reorganization, you should take into account this problem, and use the bus to transmit data between different CPU platforms to fully consider the byte order of the respective CPUs.
2. Code format
The most typical is the character encoding UTF-16, UTF-32, and both by 2 bytes and 4 bytes respectively encode the problem, which is the problem of solving the word sequence, both of the first few characters. The sequence identity is to indicate the size of the size. (Soft in order to unify the UTF format, put the UTF-8 before adding a BYTE ORDER MARK, causing the encoded file to open it on other platforms)
3.IO operation and register reading and writingThis problem often encountered in Linux's drive writing or MCU development is that the program must match the CPU size terminal mode when reading and writing the CPU peripheral register, including configuring the external chip through the bus. The size of the external chip should be considered when writing.
In fact, there is also a place where you need to consider the size of the size, that is, in communication, bit sequence inside one byte. For example, the bit sequence of the I2C and the SPI protocol follows the big end rules, that is, first send high bit bits to send low, and the UART protocol follows the small-end rules, first low-bit bits to send high. This concept involves comparative underlying things, generally do not use small partners who are underground embedded development, and will not let more detail here.
5
How do I know the word sequence of the current platform?
The most direct way is to check the manual of the CPU or the current platform. Here we talk about how to use C / C ++ to determine the word sequence of the platform.
1. Nature judgment using UNION shared memory:
2. Using the pointer judgment:
The results compiled in the Win10 + GCC6.3.3.0 environment are 40, 40 as the lowest byte of the data i, so it can be judged that the platform is a small-end storage mode.
6
How to complete the conversion of the size
I don't pull this piece, directly on the C procedure:
[1].https://thebittheories.com/little-endian-vs-big-endian-b4046c63e1f2
[2].https://www.sohu.com/a/334140526_465219
[3].https://en.wikipedia.org/wiki/Endianness
[4].https://www.zhihu.com/question/275738523/answer/382407340
[5].https://www.cnblogs.com/Alandre/p/4878841.html
Intelligent Recommendation
Big endian 1. The size is Big-end storage mode: The lower bits of data are stored in the high address of the memory, and the high bits of the data are stored in the low address of the memory. Little-e...
The size of the end
The so-called big-endian mode (Big-endian), It refers to the high byte of data, stored in the lower memory address in And the lower byte of data, stored in the high address memory, such a bit pattern ...
1, determine the size of the end: Big endian: low byte stored in high address, high byte of the status of the data stored in the low little endian mode: the low byte stored in low address, high byte o...
The size of the end
The size of the end is where they come concept big end, the small end is the concept of 'byte order' inside. It can be divided into big endian byte ordering, the little-endian, the mixing se...
Due to various problems caused by different computer architectures storage mechanism byte, word, or the like. Endian Storing a sequence of bytes is greater than the types of data in memory. Storage mo...
More Recommendation
The so-called big end: low-address high data storage small end: lower address data stored `` low Why divide the size of the end pattern of it? This is because in the computer system, we are bytes, eac...
On the size of the end
How to treat a type generally do? We should go to consider the following two aspects: 1> the size of open space 2> how to identify data in memory We want to know how the data is stored in memory...
Shallow copy: Copy is the copy, the equivalent of all the contents of an object, a copy to another object, direct copy, or that is the address of an object to another object they point to the same, th...
Shallow Size Vs Retained Size Calculator
Shallow vs. deep copy
Shallow Size Vs Retained Size Chart
Heap (heap) and stack (stack) difference: It is part of the heap and stack memory, have different roles, and a program needs to be allocated in this area. Stack memory: a first stack memory area of ...