做开发多年,一直忙于项目,从没好好的整理知识,从现在开始,尽量每周多抽时间整理知识,分享在博客,在接下来的博客中,我将为大家分享我读《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  对数据对象的存储和读取提供了更复杂的支持

Java 内存分配——Thinking in Java 4th 读书笔记相关推荐

  1. Java内存分配与垃圾回收(二)

    写在前面:主要为<深入理解Java虚拟机>的读书笔记,加上自己的思考,本篇主要讲垃圾回收,图片主要来自网络,侵删. Java与C++之间有一堵由内存动态分配和垃圾收集技术所围成的" ...

  2. 【朝花夕拾】Android性能篇之(二)Java内存分配

    前言       原文:[朝花夕拾]Android性能篇之(二)Java内存分配        在内存方面,相比于C/C++程序员,咱们java系程序员算是比较幸运的,因为对于内存的分配和回收,都交给 ...

  3. java内存分配与管理

    栈.堆.常量池虽同属Java内存分配时操作的区域,但其适用范围和功用却大不相同.本文将深入Java核心,详细讲解Java内存分配方面的知识 Java内存分配与管理是Java的核心技术之一,深入Java ...

  4. Java内存分配原理

    Java内存分配与管理是Java的核心技术之一,之前我们曾介绍过Java的内存管理与内存泄露以及Java垃圾回收方面的知识,今天我们再次深入Java核心,详细介绍一下Java在内存分配方面的知识.一般 ...

  5. java 检测硬盘原理_深入Java核心 Java内存分配原理精讲

    Java内存分配与管理是Java的核心技术之一,一般Java在内存分配时会涉及到以下区域: ◆寄存器:我们在程序中无法控制 ◆栈:存放基本类型的数据和对象的引用,但对象本身不存放在栈中,而是存放在堆中 ...

  6. 深入Java核心 Java内存分配原理精讲

    深入Java核心 Java内存分配原理精讲 Java内存分配与管理是Java的核心技术之一,之前我们曾介绍过Java的内存管理与内存泄露以及Java垃圾回收方面的知识,今天我们再次深入Java核心,详 ...

  7. 【转载】Java 内存分配全面浅析

    本文将由浅入深详细介绍Java内存分配的原理,以帮助新手更轻松的学习Java.这类文章网上有很多,但大多比较零碎.本文从认知过程角度出发,将带给读者一个系统的介绍. 本文转载自袭烽大神的博客,原文链接 ...

  8. Java核心技术- Java内存分配原理

    Java内存分配与管理是Java的核心技术之一,之前我们曾介绍过Java的内存管理与内存泄露以及Java垃圾回收方面的知识,今天我们再次深入Java核心,详细介绍一下Java在内存分配方面的知识.一般 ...

  9. java 内存分配实例_java学习(四) —— 内存分配浅析

    前言 java中有很多类型的变量.静态变量.全局变量及对象等,这些变量在java运行的时候到底是如何分配内存的呢?接下来有必要对此进行一些探究. 基本知识概念: (1)寄存器:最快的存储区, 由编译器 ...

最新文章

  1. 几个定制 iTerm2 的 tip
  2. mysql reverse 索引_降序索引和减轻索引扫描
  3. 点击Vivado的安装程序exe无法安装的解决办法
  4. 如何使用jQuery检查单选按钮?
  5. MySQL-索引优化篇(2)_使用索引扫描来优化排序
  6. spring系列-注解驱动原理及源码-spring容器创建流程
  7. 【学术相关】如何找到研究的突破点?
  8. Java 基于 TCP/IP 实现 Socket中的多客户端通信
  9. 第一次作业(李奇峰 201731062426)
  10. 从h264码流中获取图像的宽高---版本1 (移植于ffmpeg)
  11. mac 打不开 不受信任_管理不受信任的外键
  12. Java 启动参数大全
  13. aGlass学习笔记 1
  14. 干货分享! 20种数学建模方法!
  15. 尚学堂第二章作业题答案
  16. 经纬度转换度分秒工具
  17. 数字孪生3D可视化智慧化社区管理平台
  18. java 泰勒级数_使用rSymPy计算泰勒级数
  19. 浅谈网络安全之内存取证
  20. 目标决定人生,制定属于你自己的目标

热门文章

  1. DataGrid Web Control 连载之九
  2. 什么是云计算?—Vecloud 微云
  3. noip2006总结
  4. 查看文档(API) (NSString)
  5. 使用HTML文件作为中转生成WORD文档
  6. 94.cache 和虚拟存储器的功能不同
  7. 2021年结婚登记创36年新低,六大原因值得注意
  8. Proteus仿真STM32F103R6的寄存器版跑马灯程序
  9. 华为机器狗 VS 波士顿狗,谁更胜一筹?
  10. 语音识别发展必牺牲隐私?最大问题或因不符用户预期,需增透明性