作者ric2k1 (Ric)
看板EE_DSnP
标题Re: [问题] alocArray,freeArray
时间Sat Dec 9 21:11:12 2006
※ 引述《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