由买买提看人间百态

topics

全部话题 - 话题: valarry
(共0页)
k**f
发帖数: 372
1
来自主题: Programming版 - 请问一个关于 cost of pointer的问题
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.
h****e
发帖数: 2125
2
来自主题: Programming版 - template metaprogramming 的问题
大家都知道STL里面有个valarray,definition是
template
class valarray
{
...
}
有人说有个更efficient的definition就是
template
class valarray
{
static const unsigned int count = N;
...
}
说因为array size在compile time就知道了,所以可以使用例如
valarray a = { 1, 2, 3 };
我比较confused的是,如果程序中都是valarry这类的东东,是比
valarray a(3);要efficient。但是code如果都是象
void func(const unsigned int size)
{
valarray a;
...
}
这样的,有何efficiency可言呢?这只是一个小例子来反映我
对template metaprogramming的很
(共0页)