※ 引述《EEmuse2 (忘了密碼)》之銘言:
: ※ 引述《EEmuse2 (忘了密碼)》之銘言:
: : 請問alocArray5中t還是指element T的大小嗎?
: 應該說 new v.s. new[]都是傳入 alloc(t),allocArray(t),但我不太瞭解
: alloc(t)是不是說系統自動要求要一個物件大小t的空間,而allocArray(t)
: 傳入的東西又是什麼?是指幾個物件??
對 function "operator new[] (size_t t)", 系統會自動計算出所需記憶體的 #Bytes
That is, t = sizeof(T) * n + 4, where T is the class to new, and n is the
size of array (i.e. new T[n])
: 有點不知道allocArray和freeArray怎樣動手...
: : 這時我要如何知道所謂存在系統的n(array大小)??
系統在執行完 new[] 之後, 會將 n 存在 allocated memory 的最前面 4 個 Byte (i.e.
大小 = sizeof(size_t)).
至於如何看到 n, 此乃本作業的重點之ㄧ, 你可以參考 post #240.
: 也許是上面的問題 我觀念不清楚...
: : 另外在freeArray中有一行asset是要打開嗎??
: : 謝謝!
: // assert(n == getRecycleIdx(n * S + SIZE_T));
要不要打開無所謂, 這個 assert 是一定成立的.
: 老師不好意思...我問的不清不楚...只是這邊卡很久
: 我好像觀念不是很正確...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.121.136.41