“生活在堆中"是什么意思?吝啬的? [英] What does "live in the heap" mean?

查看:66
本文介绍了“生活在堆中"是什么意思?吝啬的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Objectiv C,我经常听到堆中"这个词,据我所知,它是指针所在的某种未知区域,但我试图真正了解这个词...就像我们应该让我们的财产strong,这样它就不会存在于堆中.他说,因为财产是私有的.我知道这是一个很大的不同很明显我们想要确保我们想要计算对这个对象的引用,这样自动释放就不会清理它(我们想从我目前所知的情况中保留"它),但我想确保我理解这个术语,因为它被使用得很漂亮经常.

I'm learning Objectiv C, and I hear the term "live in the heap" constantly, from what I understand its some kind of unknown area that a pointer lives in, but trying to really put head around the exact term...like "we should make our property strong so it won't live in the heap. He said that since the property is private. I know it'ss a big difference It's pretty clear that we want to make sure that we want to count the reference to this object so the autorelease wont clean it (we want to "retain" it from what i know so far), but I want to make sure I understand the term since it's being use pretty often.

欣赏

推荐答案

C(以及扩展,Objective C)程序使用三个主要内存区域来存储数据:

There are three major memory areas used by C (and by extension, Objective C) programs for storing the data:

  • 静态区域
  • 自动区域(也称为堆栈"),以及
  • 动态区域(也称为堆").

当您通过向类发送newalloc 消息来分配对象时,结果对象被分配在动态存储区中,因此该对象被称为存在于堆.所有的 Objective-C 对象都是这样(尽管引用这些对象的指针可能位于三个内存数据区域中的任何一个).相比之下,原始局部变量和数组存在"在堆栈中,而全局原始变量和数组存在于静态数据存储中.

When you allocate objects by sending their class a new or alloc message, the resultant object is allocated in the dynamic storage area, so the object is said to live in the heap. All Objective-C objects are like that (although the pointers that reference these objects may be in any of the three memory data areas). In contrast, primitive local variables and arrays "live" on the stack, while global primitive variables and arrays live in the static data storage.

只有堆对象被引用计数,尽管你可以使用 malloc/calloc/realloc 从堆分配内存,在这种情况下分配不会被引用计数:您的代码将负责决定何时释放分配的动态内存.

Only the heap objects are reference counted, although you can allocate memory from the heap using malloc/calloc/realloc, in which case the allocation would not be reference-counted: your code would be responsible for deciding when to free the allocated dynamic memory.

这篇关于“生活在堆中"是什么意思?吝啬的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆