作者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