java中的sizeof(Java sizeof)
java中的sizeof(Java sizeof)
Sizeof in Java
Does Java have an operator similar to sizeof () in the C language?
The answer is that Java does not provide any sizeof - (C) - like operator. But we should think about why Java programmers need it occasionally.
The C language programmer manages most of the data structure, storage, allocation, and sizeof () not responsible for understanding the size of the allocated storage blocks. The C storage allocator, such as malloc (), does almost nothing when it comes to object initialization: the programmer must set all the object domains that serve as pointers to the deeper layer of objects. But when all have been said and coded, the C/C++ storage allocation is quite effective.
In contrast, Java object allocation and construction are tightly integrated (it is impossible to use an object that has been allocated but not initialized). If the Java class defines a domain that is referenced as a deeper object, it is also common to set them at the construction stage. The Java object allocator therefore frequently allocates interconnected objects: object graphics. Coupled with automatic garbage collection, all of this is too convenient, and makes you feel that you don't have to worry about the details of Java storage allocation.
Of course, this is only valid for simple Java applications. Compared to C/C++, the same Java data structure often occupies more physical storage. In enterprise software development, access to the largest virtual storage on the 32 bit JVM today is a universal scalability limit. Therefore, Java programmers can benefit from sizeof () or other similar functions, because these functions can observe whether their data structures are too large or contain storage bottlenecks. Fortunately, the Java reflection allows you to write this tool quite easily.
Next, I'll discuss some of the most common misconceptions about the issue.
Error 1:, because the size of the Java type is determined, so Sizeof () is not required
Yes, Java int