Unity Automatic Memory Management(内存自动管理)官方文档笔记

本文档主要是对Unity官方教程的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于 Unity2017.3版本
参考链接: https://docs.unity3d.com/Manual/UnderstandingAutomaticMemoryManagement.html

Understanding Automatic Memory Management

了解内存自动管理

When an object, string or array is created, the memory required to store it is allocated from a central pool called the heap. When the item is no longer in use, the memory it once occupied can be reclaimed and used for something else. In the past, it was typically up to the programmer to allocate and release these blocks of heap memory explicitly with the appropriate function calls. Nowadays, runtime systems like Unity’s Mono engine manage memory for you automatically. Automatic memory management requires less coding effort than explicit allocation/release and greatly reduces the potential for memory leakage (the situation where memory is allocated but never subsequently released).
当一个对象、字符串或数组被创建时,存储它所需的内存是从一个名为堆的中央池中分配的。当变量不再使用时,它曾经占用的内存可以被回收,并用于其他用途。在过去,通常由程序员根据适当的函数调用显式地分配和释放这些堆内存块。现在,像Unity的Mono引擎这样的运行时系统会自动为你管理内存。自动内存管理比显式分配/释放有更少的编码工作,并且极大地降低了内存泄漏(内存被分配但从未被释放的情况)。

Value and Reference Types

值和引用类型

When a function is called, the values of its parameters are copied to an area of memory reserved for that specific call. Data types that occupy only a few bytes can be copied very quickly and easily. However, it is common for objects, strings and arrays to be much larger and it would be very inefficient if these types of data were copied on a regular basis. Fortunately, this is not necessary; the actual storage space for a large item is allocated from the heap and a small “pointer” value is used to remember its location. From then on, only the pointer need be copied during parameter passing. As long as the runtime system can locate the item identified by the pointer, a single copy of the data can be used as often as necessary.
当一个函数被调用时,它的参数值被复制到一个特定调用而保留的内存区域。只占用几个字节的数据类型可以非常快速和容易地复制。然而,多个对象、字符串和数组的规模要大得多,如果这些类型的数据经常被复制,那么它将非常低效。幸运的是,这并不是必要的;一个大的变量的实际存储空间是从堆中分配的,一个小的“指针”值用来记住它的位置。从那时起,在参数传递过程中只需要复制指针。只要运行时系统能够定位指针标识的对象,就可以在必要时使用此指针的数据副本。

Types that are stored directly and copied during parameter passing are called value types. These include integers, floats, booleans and Unity’s struct types (eg, Color and Vector3). Types that are allocated on the heap and then accessed via a pointer are called reference types, since the value stored in the variable merely “refers” to the real data. Examples of reference types include objects, strings and arrays.
在参数传递过程中直接存储和复制的类型称为值类型。这些包括整数、浮点数、布尔值和Unity的结构类型(如颜色和Vector3)。被分配到堆上的类型,然后通过一个指针访问的类型称为引用类型,因为变量中存储的值仅仅是“引用”到真实的数据。参考类型的例子包括对象、字符串和数组。

Allocation and Garbage Collection

分配与垃圾回收

The memory manager keeps track of areas in the heap that it knows to be unused. When a new block of memory is requested (say when an object is instantiated), the manager chooses an unused area from which to allocate the block and then removes the allocated memory from the known u

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值