虽然这些天做了大量的基准测试,但我偶然发现了一些非常令人不安/有趣/新的东西.经过一些研究越来越多(我无法相信),似乎windows xp(以及可能所有其他版本)运行程序的速度是安全模式的3倍.
以这个小程序为例:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
long i,j,k;
printf ("Starting...\n");
k = 12;
for (i = 0; i < 20000; i++)
for (j = 100000; j > 0; j--)
k = k * 12;
printf ("Done... k =%d", k); // just using k here to prevent the whole block isn't optimized away.
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在我的2.4 Ghz计算机上,在安全模式下执行需要约2.5秒,而在正常模式下执行需要约8秒.(ThreadPriority = TIMECRITICAL,ProcessClass = REALTIME).即使我在这个非常正常的Windows模式下在vmware-linux会话中编译并启动该代码,它执行得更快(大约5.5秒).
我也做了很多cpu周期测量,实际上安全模式的结果看起来更像是你应该期望的,因为处理的指令数量.
那我错过了什么?任何人都可以捣乱我吗?
所有指针和提示都表示赞赏,Thanx.
解决了!我很抱歉,这个问题与我糟糕的alienware m15x有关,由于某种原因,它显然会减少到其cpu功率的1/3 - 除非你使用邪恶工具(ThrottleStop.exe)将其提升到正常速度.非常抱歉浪费你的时间.:(
陷入另一个模板问题:
问题:我想在对象是指针的情况下部分地专门化一个容器类(foo),并且我只想专门使用delete-method.应该是这样的:
lib代码
template <typename T>
class foo
{
public:
void addSome (T o) { printf ("adding that object..."); }
void deleteSome (T o) { printf ("deleting that object..."); }
};
template <typename T>
class foo <T *>
{
public:
void deleteSome (T* o) { printf ("deleting that PTR to an object..."); }
};
Run Code Online (Sandbox Code Playgroud)
用户代码
foo<myclass> myclasses;
foo<myclass*> myptrs;
myptrs.addSome (new myclass());
Run Code Online (Sandbox Code Playgroud)
这导致编译器告诉我myptrs没有一个名为addSome的方法.为什么?
感谢名单.
LIB
template <typename T>
class foobase
{
public:
void addSome (T o) { printf …Run Code Online (Sandbox Code Playgroud) 我有一个Mac Osx应用程序提交到Mac App Store - 它支持8种语言.
它主要用纯C++编写,我使用自己的本地化处理,所以我不使用XCode提供的任何本地化字符串.
问题:我在哪里可以设置这些语言,因此它会显示在Mac App Store中?
感谢你的帮助,罗曼
g ++编译器给出了这个错误:expect`;' 在'它'之前
template <typename T>
class myList : public std::list<T>
{
public:
void foo ()
{
std::list<T>::iterator it; // compiler error as above mentioned, why ???
}
};
Run Code Online (Sandbox Code Playgroud)
谢谢.
我使用debian和g ++.编译时,我得到如下错误消息:
在静态成员函数中ΓÇÿstaticvoid*v4 :: _ mb_blocs :: operator new(size_t)ΓÇÖ:
我能告诉gcc用utf-8做什么输出吗?
我有一个关于嵌套模板和赋值运算符重写的问题.假设我想要一个引用计数类模板_reference.这个_reference现在只是保存一个指向ref-counting对象的指针.现在的问题是,只要我使用简单的类或结构进行此操作,这一切都可以正常工作.例如._reference ...,
但是现在我想创建一个类模板,它是对std-vector的引用,它转发了它所拥有的类.
不,我只是发布代码:(它现在没有做引用和那些东西,它只是提取我遇到的问题)
template <typename T>
class _reference
{
private:
T* p_;
public:
// !!! this assignment seems only to work, when T is no class template already...
void operator= (T* r)
{
p_ = r;
}
// WHILE this ALWAYS works as well...
void simplySetIt (T* r)
{
p_ = r;
}
};
template <typename T>
class _ref_vector : public _reference<vector<T> >
{
};
void test2 ()
{
_reference<vector<long> > ref_ptr2;
_ref_vector<long> ref_ptr3;
ref_ptr2 = new vector<long>; // …Run Code Online (Sandbox Code Playgroud) 我又用模板卡住了.
说,我想实施一个guicell系统.每个guicell都可以包含许多儿童guicell.到目前为止,树结构如此.在std-c ++中,我会选择sthg.喜欢:
template <typename T>
class tree
{
public:
void add (T *o) { _m_children.push_back (o); }
void remove (T *o) { ... };
list<T*> _m_children;
};
class _cell : public tree<_cell>
{
public:
_cell () { x = 0; y =0; }
long x,y;
};
Run Code Online (Sandbox Code Playgroud)
但是现在我想要更进一步,如果编码人员愿意的话,让细胞可以参考.所以我基本上为此目的实现了一个refTree类,它也只需要指针(_cell*)作为输入.
template <typename T>
class refTree
{
public:
void add (T *o) { _ref<T> r = o; _m_children.push_back (r); }
void remove (T *o) { ... }
list<_ref<T> > _m_children;
};
Run Code Online (Sandbox Code Playgroud)
这仍然工作正常.运用
class …Run Code Online (Sandbox Code Playgroud) c++ ×5
templates ×4
g++ ×2
gcc ×1
inheritance ×1
iterator ×1
linux ×1
macos ×1
multilingual ×1
nested ×1
performance ×1
recursion ×1
windows ×1
xcode ×1