h**o 发帖数: 347 | 1 想自已写一个 matrix class并用 valarray作成员变量存储数据
现在的问题是用指向valarray的指针好还是valarray直接作变量好
CS的同学给我建议说如果要频繁寻址,用指针的话开销会比较大
请问是这样吗?
我的另一个concern是直接作变量,放在stack 上面,是不是有大小上的限制?
那在设计 member variable的时候用指针又有什么好处?
新手问题啊,多谢指教 | k**f 发帖数: 372 | 2 Although it is an implementation detail, the fact that size of a valarray
can be determined at runtime indicates that the underlying memory of
valarray is very likely to be allocated on heap, not on stack. So the size
of a valarry variable may not be directly related to the size of the data
inside it. So I'd say use the valarry directly. You may try to initiate a
very big valarry to see if there's any stack overflow issue. At least some
compiler will complain when it happens.
Good luck. |
|