久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <i id='fkD6q'><tr id='fkD6q'><dt id='fkD6q'><q id='fkD6q'><span id='fkD6q'><b id='fkD6q'><form id='fkD6q'><ins id='fkD6q'></ins><ul id='fkD6q'></ul><sub id='fkD6q'></sub></form><legend id='fkD6q'></legend><bdo id='fkD6q'><pre id='fkD6q'><center id='fkD6q'></center></pre></bdo></b><th id='fkD6q'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fkD6q'><tfoot id='fkD6q'></tfoot><dl id='fkD6q'><fieldset id='fkD6q'></fieldset></dl></div>
  1. <tfoot id='fkD6q'></tfoot>
  2. <legend id='fkD6q'><style id='fkD6q'><dir id='fkD6q'><q id='fkD6q'></q></dir></style></legend>

        <bdo id='fkD6q'></bdo><ul id='fkD6q'></ul>

    1. <small id='fkD6q'></small><noframes id='fkD6q'>

      在java中,使用byte或short而不是int和float而不是d

      In java, is it more efficient to use byte or short instead of int and float instead of double?(在java中,使用byte或short而不是int和float而不是double更有效嗎?)
          <i id='7CnYQ'><tr id='7CnYQ'><dt id='7CnYQ'><q id='7CnYQ'><span id='7CnYQ'><b id='7CnYQ'><form id='7CnYQ'><ins id='7CnYQ'></ins><ul id='7CnYQ'></ul><sub id='7CnYQ'></sub></form><legend id='7CnYQ'></legend><bdo id='7CnYQ'><pre id='7CnYQ'><center id='7CnYQ'></center></pre></bdo></b><th id='7CnYQ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7CnYQ'><tfoot id='7CnYQ'></tfoot><dl id='7CnYQ'><fieldset id='7CnYQ'></fieldset></dl></div>
              <tbody id='7CnYQ'></tbody>

              • <bdo id='7CnYQ'></bdo><ul id='7CnYQ'></ul>

                <small id='7CnYQ'></small><noframes id='7CnYQ'>

              • <tfoot id='7CnYQ'></tfoot><legend id='7CnYQ'><style id='7CnYQ'><dir id='7CnYQ'><q id='7CnYQ'></q></dir></style></legend>
              • 本文介紹了在java中,使用byte或short而不是int和float而不是double更有效嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我注意到我總是使用 int 和 doubles,無論數字需要多大或多小.那么在java中,使用byteshort代替intfloat代替雙?

                I've noticed I've always used int and doubles no matter how small or big the number needs to be. So in java, is it more efficient to use byte or short instead of int and float instead of double?

                所以假設我有一個包含大量整數和雙精度數的程序.如果我知道這個數字合適,是否值得將我的整數更改為字節或短褲?

                So assume I have a program with plenty of ints and doubles. Would it be worth going through and changing my ints to bytes or shorts if I knew the number would fit?

                我知道 java 沒有無符號類型,但如果我知道這個數字只是正數,我還能做些什么嗎?

                I know java doesn't have unsigned types but is there anything extra I could do if I knew the number would be positive only?

                我所說的高效主要是指處理.我假設如果所有變量都是一半大小,那么垃圾收集器會快得多,并且計算也可能會更快一些.(我想因為我正在使用 android,所以我也需要有點擔心 ram)

                By efficient I mostly mean processing. I'd assume the garbage collector would be a lot faster if all the variables would be half size and that calculations would probably be somewhat faster too. ( I guess since I am working on android I need to somewhat worry about ram too)

                (我假設垃圾收集器只處理對象而不是原始對象,但仍會刪除廢棄對象中的所有原始對象,對吧?)

                (I'd assume the garbage collector only deals with Objects and not primitive but still deletes all the primitives in abandoned objects right? )

                我用我擁有的一個小型 android 應用程序進行了嘗試,但并沒有真正注意到有什么不同.(雖然我沒有科學地"測量任何東西.)

                I tried it with a small android app I have but didn't really notice a difference at all. (Though I didn't "scientifically" measure anything.)

                我認為它應該更快更高效是不是錯了?我不想經歷并改變一個龐大的程序中的所有內容,以發現我浪費了我的時間.

                Am I wrong in assuming it should be faster and more efficient? I'd hate to go through and change everything in a massive program to find out I wasted my time.

                當我開始一個新項目時,是否值得從頭開始?(我的意思是我認為每一點都會有所幫助,但如果是這樣的話,為什么似乎沒有人這樣做.)

                Would it be worth doing from the beginning when I start a new project? (I mean I think every little bit would help but then again if so, why doesn't it seem like anyone does it.)

                推薦答案

                我認為它應該更快更高效是不是錯了?我不想經歷并改變一個龐大的程序中的所有內容,以發現我浪費了我的時間.

                Am I wrong in assuming it should be faster and more efficient? I'd hate to go through and change everything in a massive program to find out I wasted my time.

                簡答

                是的,你錯了.在大多數情況下,它在使用的空間方面差別不大.

                不值得嘗試優化...除非您有明確的證據表明需要優化.如果您確實需要特別優化對象字段的內存使用,您可能需要采取其他(更有效的)措施.

                It is not worth trying to optimize this ... unless you have clear evidence that optimization is needed. And if you do need to optimize memory usage of object fields in particular, you will probably need to take other (more effective) measures.

                Java 虛擬機使用偏移量(實際上)是 32 位原始單元大小的倍數來模擬堆棧和對象字段.因此,當您將局部變量或對象字段聲明為(例如)byte 時,變量/字段將存儲在 32 位單元格中,就像 int 一樣.

                The Java Virtual Machine models stacks and object fields using offsets that are (in effect) multiples of a 32 bit primitive cell size. So when you declare a local variable or object field as (say) a byte, the variable / field will be stored in a 32 bit cell, just like an int.

                這有兩個例外:

                • longdouble 值需要 2 個原始 32 位單元
                • 原始類型數組以打包形式表示,因此(例如)字節數組每個 32 位字包含 4 個字節.
                • long and double values require 2 primitive 32-bit cells
                • arrays of primitive types are represent in packed form, so that (for example) an array of bytes hold 4 bytes per 32bit word.

                因此 可能 值得優化 longdouble ...以及大型基元數組的使用.但一般不會.

                So it might be worth optimizing use of long and double ... and large arrays of primitives. But in general no.

                理論上,JIT 可能能夠優化這一點,但實際上我從未聽說過有這樣的 JIT.一個障礙是 JIT 通常在創建正在編譯的類的實例之后才能運行.如果 JIT 優化了內存布局,您可以擁有兩個(或更多)風味".同一類的對象......這將帶來巨大的困難.

                In theory, a JIT might be able to optimize this, but in practice I've never heard of a JIT that does. One impediment is that the JIT typically cannot run until after there instances of the class being compiled have been created. If the JIT optimized the memory layout, you could have two (or more) "flavors" of object of the same class ... and that would present huge difficulties.

                查看@meriton 答案中的基準測試結果,似乎使用 shortbyte 而不是 int 會導致乘法性能下降.事實上,如果你孤立地考慮這些操作,懲罰是巨大的.(你不應該孤立地考慮它們......但這是另一個話題.)

                Looking at the benchmark results in @meriton's answer, it appears that using short and byte instead of int incurs a performance penalty for multiplication. Indeed, if you consider the operations in isolation, the penalty is significant. (You shouldn't consider them in isolation ... but that's another topic.)

                我認為解釋是 JIT 可能在每種情況下都使用 32 位乘法指令進行乘法運算.但在 byteshort 的情況下,它執行 extra 指令將中間 32 位值轉換為 byteshort 在每個循環迭代中.(理論上,這種轉換可以在循環結束時完成一次......但我懷疑優化器是否能夠解決這個問題.)

                I think the explanation is that JIT is probably doing the multiplications using 32bit multiply instructions in each case. But in the byte and short case, it executes extra instructions to convert the intermediate 32 bit value to a byte or short in each loop iteration. (In theory, that conversion could be done once at the end of the loop ... but I doubt that the optimizer would be able to figure that out.)

                無論如何,這確實指向另一個問題,即切換到 shortbyte 作為優化.它可能會使性能更差 ...在算術和計算密集型算法中.

                Anyway, this does point to another problem with switching to short and byte as an optimization. It could make performance worse ... in an algorithm that is arithmetic and compute intensive.

                我知道 java 沒有無符號類型,但如果我知道這個數字只是正數,我還能做些什么嗎?

                I know java doesn't have unsigned types but is there anything extra I could do if I knew the number would be positive only?

                沒有.無論如何,不??是在性能方面.(在 Integer、Long 等中有一些方法可以將 int、long 等作為無符號處理.但這些并沒有帶來任何性能優勢.這不是他們的目的.)

                No. Not in terms of performance anyway. (There are some methods in Integer, Long, etc for dealing with int, long, etc as unsigned. But these don't give any performance advantage. That is not their purpose.)

                (我假設垃圾收集器只處理對象而不是原始對象,但仍會刪除廢棄對象中的所有原始對象,對吧?)

                (I'd assume the garbage collector only deals with Objects and not primitive but still deletes all the primitives in abandoned objects right? )

                正確.對象的字段是對象的一部分.當對象被垃圾收集時,它就會消失.同樣,當收集陣列時,陣列的單元格就會消失.當字段或單元格類型是原始類型時,值將存儲在字段/單元格中......它是對象/數組的一部分......并且已被刪除.

                Correct. A field of an object is part of the object. It goes away when the object is garbage collected. Likewise the cells of an array go away when the array is collected. When the field or cell type is a primitive type, then the value is stored in the field / cell ... which is part of the object / array ... and that has been deleted.

                這篇關于在java中,使用byte或short而不是int和float而不是double更有效嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                How to convert Integer to int?(如何將整數轉換為整數?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                Inconsistent behavior on java#39;s ==(java的行為不一致==)
                Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                1. <i id='2fizn'><tr id='2fizn'><dt id='2fizn'><q id='2fizn'><span id='2fizn'><b id='2fizn'><form id='2fizn'><ins id='2fizn'></ins><ul id='2fizn'></ul><sub id='2fizn'></sub></form><legend id='2fizn'></legend><bdo id='2fizn'><pre id='2fizn'><center id='2fizn'></center></pre></bdo></b><th id='2fizn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2fizn'><tfoot id='2fizn'></tfoot><dl id='2fizn'><fieldset id='2fizn'></fieldset></dl></div>

                  <small id='2fizn'></small><noframes id='2fizn'>

                  <tfoot id='2fizn'></tfoot>
                    <tbody id='2fizn'></tbody>
                  <legend id='2fizn'><style id='2fizn'><dir id='2fizn'><q id='2fizn'></q></dir></style></legend>

                    • <bdo id='2fizn'></bdo><ul id='2fizn'></ul>

                          主站蜘蛛池模板: 91啪影院| 日韩图区| 夜夜骚| 在线观看视频91 | 日本一区二区三区四区 | 在线欧美视频 | 欧美激情第一区 | 国产99久久精品一区二区永久免费 | 国产精品久久久久久婷婷天堂 | 成人在线不卡 | 欧美日韩视频 | 欧美a级成人淫片免费看 | 欧美一区视频 | 国产福利在线 | 日韩中文字幕网 | 一区二区三区中文字幕 | 日本天堂视频 | 久久成人人人人精品欧 | 欧美久久久久久久久中文字幕 | 日韩中文一区二区三区 | 91国内精品| 日韩精品在线免费观看 | 一级毛片在线播放 | 色婷婷综合网 | 欧美一级淫片免费视频黄 | 精品99久久久久久 | 亚洲日本欧美日韩高观看 | 成人综合视频在线 | 浴室洗澡偷拍一区二区 | 成人午夜视频在线观看 | 视频一区二区在线观看 | 日韩精品免费 | 成人免费黄色片 | 91精品国产91久久久久久 | 91亚洲精品国偷拍自产在线观看 | 日批av| 中文字幕在线看第二 | 亚洲国产一区二区视频 | 五月天婷婷狠狠 | 久久国产婷婷国产香蕉 | 9999视频|