SizeOf for Java

zhaozj2021-02-12  131

Q: Is there a similar operator in Java in and c?

A: Simple saying that Java does not provide an operator similar to the SIZEOF () in C. But we can analyze why Java programs often need him.

A C programmer needs to define the data structure, allocate memory, and sizeof () is necessary to know the memory block size to allocate memory. In addition, C-memory distributors, such as malloc () basically do not do anything until the initialization of objects: Programmer Must Set All Object Fields That Are Pointers to Further Objects. But when All IS Said and Coded, C / C Memory Allocation IS Quite Efficient.

In contrast, Java object assignment and construct is connected together (objects that use allocated but not initialized). IF a Java Class defines Fields That Are References to further Objects, IT IS Also Common To set them at construction time Allocating a Java object therefore frequently allocates numerous interconnected object instances:. an object graph and automatic garbage collection contact with, this is all too convenient and can make you feel like you never have to worry about Java memory allocation details..

Of course, these things are for simple Java applications. Compared with C / C , the equivalent Java data structure needs to take more physical memory. In enterprise-class software development, now 32-bit JVM (Java The maximum available diversion of the virtual machine is usually SCALABILITY CONSTRAINT. Therefore, Java programmers should still be beneficial to SizeOf () or other similar stuff to note whether his data structure is getting Too Large or Contain Memory Bottlenecks. Fortunately, Java Reflection allows you to easily write these tools.http://www.javaworld.com/javaworld/javaqa/2003-12/02-QA-1226-SIZEOF.html?

转载请注明原文地址:https://www.9cbs.com/read-7129.html

New Post(0)