作者ric2k1 (Ric)
看板EE_DSnP
标题Re: [问题] hw1 3
时间Wed Oct 18 15:37:25 2006
※ 引述《personhuang (Person)》之铭言:
: 请问一下 记忆体方面的概念
: 讲义上有写 heap 是pointer 的content
: stack 是local variable
: 那reference 是放在哪 内容是在哪 由reference的对象决定?
"reference" is just an alias in the "symbol table". It does not take any space
in either the heap or stack memory.
: 那对於array来说 array 他内容是放heap?
It depends on whether it is a local array variable.
For example,
----------
void f()
{
int arr[10];
}
---------
"arr" is a local variable in "f()" so it will reside in the stack memory with
size = sizeof(int) * 10.
Another example,
------------
void g()
{
int* arr = new int[10];
}
------------
"arr" is STILL A LOCAL VARIABLE in "f()". However, it will only take 4 bytes
in the stack memory (storing the address of "new int[10]"). The memory it
points to (total sizeof(int) * 10 [注 (i)] ) will reside in the heap memory.
: 还有能否解释 如果是单纯因为结束f() 因此i位址值释放 而烂掉 那为何每次烂的一样
: 还有 (v) 有人overlap 有人不会overlap 是因为什麽
This is a machine/platform dependent issue.
: 不知道有没有描述的清楚 谢谢指导
[Hint] Please note that when a function is called, it will take up some memory
in the stack memory. They are for the "returned address", "parameters", etc.
[注 1] Actually it will take 4 bytes more of memory ==> to store that the
size of array is "10". We will talk about the in the "Memory Management" unit.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.21.240
1F:推 personhuang:thx 10/18 22:47