日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Java 内存分配——Thinking in Java 4th 读书笔记

發布時間:2025/4/16 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java 内存分配——Thinking in Java 4th 读书笔记 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

做開發多年,一直忙于項目,從沒好好的整理知識,從現在開始,盡量每周多抽時間整理知識,分享在博客,在接下來的博客中,我將為大家分享我讀《Java編程思想4th》英文版讀書筆記,一來便于知識的梳理,二來分享給需要的朋友,評價很高的一本書,推薦大家閱讀,因為書的邊幅比較長,如果不想閱讀整本書歡迎來我的博客,我會定期分享書的重點內容,以翻譯的形式展現。

There are five different places to store data:?

存儲數據的地方有5個

1. Registers. This is the fastest storage because it exists in a place different from that of other storage: inside the?

1.寄存器這是最快的存儲,因為它存在的位置與其他的存儲方式有別:它位于處理器中。

processor. However, the number of registers is severely limited, so registers are allocated as they are needed. You?

然而,寄存器的數量是嚴格限制的,所以寄存器是當它需要時才分配的。

don’t have direct control, nor do you see any evidence in your programs that registers even exist (C & C++, on the?

你既不能直接去控制,也看不到寄存器在你程序中存在的跡象。(然而,C 和C++允許你去建議編譯器去分配寄存器)

other hand, allow you to suggest register allocation to the compiler). ?


2. The stack. This lives in the general random-access memory (RAM) area, but has direct support from the processor?

2.棧。它位于通用隨機存儲器區域,但可以通過它的棧指針從處理器那里獲得直接的支持。

via its stack pointer. The stack pointer is moved down to create new memory and moved up to release that memory.?

棧指針向下移動是創建新的存儲空間,向上移動是釋放存儲空間。

This is an extremely fast and efficient way to allocate storage, second only to registers. The Java system must know,?

這是一種十分快速并且有效的方法去分配內存,僅次于寄存器 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

while it is creating the program, the exact lifetime of all the items that are stored on the stack. This constraint places?

當創建一個程序時,Java系統必須知道存儲在棧上所有項的準確生命周期。 ? ? ? ? ? ? ? ? ?

limits on the flexibility of your programs, so while some Java storage exists on the stack—in particular, object?

這個約束一定程度上限制了你的程序的靈活性,所以當一些Java存儲在棧上時,特別是對象的引用——Java對象本身

references—Java objects themselves are not placed on the stack. ?

并沒有存放在堆棧上


3. The heap. This is a general-purpose pool of memory (also in the RAM area) where all Java objects live. The?

3.堆。 這是通用目的的存儲池(同樣是在隨機存儲區域),也就是Java對象存儲的地方,

nice thing about the heap is that, unlike the stack, the compiler doesn’t need to know how long that storage must?

不像棧那樣,堆的一個好處是,編譯器并不需要知道數據在堆上存儲的時間。

stay on the heap. Thus, there’s a great deal of flexibility in using storage on the heap. Whenever you need an object,?

因此,使用堆來存儲擁有極大的靈活性。 ? ?當你需要一個對象(不是指你想相處的對象,開個小玩笑),

you simply write the code to create it by using new, and the storage is allocated on the heap when that code is?

你只需要簡單的通過new 來創建它, 并且當代碼運行的時候內存才會在堆上分配。

executed. Of course there’s a price you pay for this flexibility: It may take more time to allocate and clean up heap?

當然,擁有靈活性是有代價的,它可能比棧花更多的時間去分配和清理堆內存。

storage than stack storage . ?


4. Constant storage. Constant values are often placed directly in the program code, which is safe since?

4.常量存儲。 ?常量值經常被放在程序代碼里, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 這是安全的

they can never change. Sometimes constants are cordoned off by themselves so that they can be optionally placed in?

因為它們永遠不會改變。 ?有時候常量被它們自己隔離 以至于它們能被選擇性的放在只讀存儲區,在嵌入式系統。

read-only memory (ROM), in embedded systems



?

?5. Non-RAM storage. If data lives completely outside a program, it can exist while the program is not?

5.非隨機存儲器存儲。如果數據存在于程序之外,它可以存在而程序沒有跑的時候,

running, outside the control of the program. The two primary examples of this are streamed objects, in which objects?

不受程序的控制。 ?有兩個重要的栗子是流對象, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 也就是對象被轉換成

are turned into streams of bytes, generally to be sent to another machine, and persistent objects, in which the objects?

字節流,通常被發送到另一臺機器, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?還有一個栗子是持久性對象,

are placed on disk so they will hold their state even when the program is terminated. The trick with these types of?

它們被放在磁盤中,所以盡管程序終止了它們也會保持它們的狀態。

storage is turning the objects into something that can exist on the other medium, and yet can be resurrected into a?

這些類型存儲的技巧是將對象轉換成可以存放在其他媒體上的東西。

regular RAMbased object when necessary. Java provides support for lightweight persistence, and mechanisms such as?

并且能夠在需要的時候重新復活成隨機存儲器類型的對象。Java提供了對輕量級持久性的支持,

JDBC and Hibernate provide more sophisticated support for storing and retrieving object information in databases.?

JDBC ?和Hibernate ?對數據對象的存儲和讀取提供了更復雜的支持

?
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的Java 内存分配——Thinking in Java 4th 读书笔记的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。