关于堆对象的简单问题。 [英] A simple question on heap objects.

查看:51
本文介绍了关于堆对象的简单问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我想知道一些事情。这可能很愚蠢但是,如果堆对象中有数组,那么数组将驻留在哪里?

如果在堆中,那么它的mem位置如何被释放?


我无法理解它。

谢谢!

Hi all. I''d like to know something. This may be silly but, if there is an array inside a heap object, where will the array reside?
If in heap too, then how does its mem location get freed?

I can''t get my mind worked around it.
Thanks!

推荐答案


大家好。我想知道一些事情。这可能很愚蠢但是,如果堆对象中有数组,那么数组将驻留在哪里?

如果在堆中,那么它的mem位置如何被释放?


我无法解决它的问题。

谢谢!
Hi all. I''d like to know something. This may be silly but, if there is an array inside a heap object, where will the array reside?
If in heap too, then how does its mem location get freed?

I can''t get my mind worked around it.
Thanks!



如果数组是结构/类对象的成员,它只是内存的一部分

分配给整个结构/类宾语。如果整个事物存储在堆栈上(想想局部变量),那么数组将成为它的一部分,并且也存储在堆栈的

上。如果这个东西存在于堆中的某个地方(想想malloc或者新的)

阵列也会在那里。


这里是一个极端的C中的简单例子;考虑以下结构:

If an array is a member of a structure/class object it is just part of the memory
allocated for the entire structure/class object. If the entire thing was stored on
the stack (think of local variables), the array will be part of it and also stored on
the stack. If the thing resides somewhere in the heap (think of malloc or new)
the array will be somewhere in there too.

Here''s an extremely simple example in C; consider the following struct:

展开 | 选择 | Wrap | 行号


是的,现在我记得。但它如何被释放?
Yes, now i remember. But how does it get freed?



是的,现在我记得了。但它如何得到释放?
Yes, now i remember. But how does it get freed?



给出我之前回复的示例:

given the example from my previous reply:

展开 | 选择 | Wrap | 行号


这篇关于关于堆对象的简单问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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