java实现sizeof_java中的sizeof(Java sizeof).doc

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值