青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

tommy

It's hard to tell the world we live in is either a reality or a dream
posts - 52, comments - 17, trackbacks - 0, articles - 0
  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

《windows圖形編程》有講:

KTimer.h

#pragma?once
inline?unsigned?__int64?GetCycleCount(
void )
{
????_asm?_emit?
0x0F
????_asm?_emit?
0x31
}


class ?KTimer??
{
????unsigned?__int64?m_startcycle;
public :
????unsigned?__int64?m_overhead;????
// RTSC指令的運行時間

????KTimer()
????
{
????????m_overhead?
= ? 0 ;
????????Start();
????????m_overhead?
= ?Stop();
????}

????
void ?Start();
????unsigned?__int64?Stop();
????unsigned?unsigned?GetCPUSpeed();

}
;

KTimer.cpp
#include?"KTimer.h"

#include?
<iostream>
#include?
<windows.h>


void?KTimer::Start()
{
????m_startcycle?
=?GetCycleCount();
}

unsigned?__int64?KTimer::Stop()
{
????
return?GetCycleCount()?-?m_startcycle?-?m_overhead;
}

unsigned?unsigned?KTimer::GetCPUSpeed()
{
????cout?
<<?"開始測試?cpu速度.."?<<?endl;
????Start();
????Sleep(
1000);
????unsigned?cputime?
=?Stop();
????unsigned?cpuspeed10?
=?(unsigned)(cputime/100000);
????cout?
<<?"CPU速度?每秒:"?<<?cputime?<<?"?clocks"?<<?endl;
????
return?cpuspeed10?==?0???1?:?cpuspeed10;
}

用法:
#include?"stdafx.h"
#include?
<tchar.h>
#include?
<windows.h>
#include?
<iostream>

#include?
"KTimer.h"

int?main(int?argc,?char*?argv[])
{????
????KTimer?timer;

????unsigned?cpuspeed10?
=?timer.GetCPUSpeed();

????timer.Start();
????
//做耗時操作
????
????unsigned?time?
=?timer.Stop();

????TCHAR?mess[
128];
????wsprintf(mess,_T(
"耗時:%d?ns"),?time?*?10000?/?cpuspeed10);
????cout?
<<?mess?<<?endl;

????
return?0;
}

posted @ 2006-04-01 11:10 Tommy Liang 閱讀(855) | 評論 (1)編輯 收藏

范圍廣闊啊。
1、地圖  從A到B,哪條路花費最少 / 哪條是最快的路線,如果身上只能花N$,那么應該選擇哪條路?
2、超文本  圖處理算法是搜索引擎的基本組成部分
3、電路  如“能否將此電路做在芯片上而不出現任何線路交叉”
4、調度  如何滿足給定約束,又節省時間
5、事務   如對通信線路的布線從而高效地處理通信;對市場購銷現金流的監測以便加強對市場實際情況的了解。
6、匹配   如應聘人員與單位機構的匹配
7、網絡   計算機網絡的維護,如何調整節點以便確保某些站點或連接不至于處于太“要害”的地位。
8、程序結構   如何最佳地為程序分配資源以便做到最高效?


值得研究。

posted @ 2006-02-06 09:49 Tommy Liang 閱讀(451) | 評論 (0)編輯 收藏

書里面說的這個詞:
型別計算的邊界標記

NullType只有聲明沒有定義。

class NullType;
這是為了表達“我不是個令人感興趣的型別”,可以作為“找不到型別”的消息標記。類似\0這樣。

EmptyType,就是一個空類
struct EmptyType {};

這是可被繼承的合法型別,可以作為template的缺省參數型別。

posted @ 2006-02-06 01:29 Tommy Liang 閱讀(956) | 評論 (0)編輯 收藏

std::type_info類可以在執行期間查詢對象型別,但使用起來比較麻煩。為此定義了wrapper

下面的代碼出自 Loki庫:
總得來說是提供了std::type_info的所有成員函數;
提供了value語義,即public copy構造函數和public assignment操作符;
定義了 operator< 和 operator== 等

namespace Loki
{
////////////////////////////////////////////////////////////////////////////////
// class TypeInfo
// Purpose: offer a first-class, comparable wrapper over std::type_info
////////////////////////////////////////////////////////////////////////////////

    
class TypeInfo
    
{
    
public:
        
// Constructors
        TypeInfo(); // needed for containers
        TypeInfo(const std::type_info&); // non-explicit

        
// Access for the wrapped std::type_info
        const std::type_info& Get() const;
        
// Compatibility functions
        bool before(const TypeInfo& rhs) const;
        
const char* name() const;

    
private:
        
const std::type_info* pInfo_;
    }
;
    
// Implementation
    
    inline TypeInfo::TypeInfo()
    
{
        
class Nil {};
        pInfo_ 
= &typeid(Nil);
        assert(pInfo_);
    }

    
    inline TypeInfo::TypeInfo(
const std::type_info& ti)
    : pInfo_(
&ti)
    
{ assert(pInfo_); }
    
    inline 
bool TypeInfo::before(const TypeInfo& rhs) const
    
{
        assert(pInfo_);
        
return pInfo_->before(*rhs.pInfo_) != 0;
    }


    inline 
const std::type_info& TypeInfo::Get() const
    
{
        assert(pInfo_);
        
return *pInfo_;
    }

    
    inline 
const char* TypeInfo::name() const
    
{
        assert(pInfo_);
        
return pInfo_->name();
    }


// Comparison operators
    
    inline 
bool operator==(const TypeInfo& lhs, const TypeInfo& rhs)
    
return (lhs.Get() == rhs.Get()) != 0; }

    inline 
bool operator<(const TypeInfo& lhs, const TypeInfo& rhs)
    
return lhs.before(rhs); }

    inline 
bool operator!=(const TypeInfo& lhs, const TypeInfo& rhs)
    
return !(lhs == rhs); }    
    
    inline 
bool operator>(const TypeInfo& lhs, const TypeInfo& rhs)
    
return rhs < lhs; }
    
    inline 
bool operator<=(const TypeInfo& lhs, const TypeInfo& rhs)
    
return !(lhs > rhs); }
     
    inline 
bool operator>=(const TypeInfo& lhs, const TypeInfo& rhs)
    
return !(lhs < rhs); }
}

posted @ 2006-02-06 01:20 Tommy Liang 閱讀(4101) | 評論 (0)編輯 收藏

在編譯時刻,在Conversion類中產生兩個常數(編譯器幫忙計算)

template <class T,class U>
class Conversion
{
    
//
public:
    
enum { exists2Way = exists && Conversion<U,T>::exists };
        
enum { sameType = false };
}
;
一個是 exists2Way,表示是否可以兩個類型互相轉換,
sameType 表示 T和U是否同一個類型。
不過,雖然書里這么說,我怎么都搞不懂為什么這樣可以,測試也是不對的,難道這個sameType的寫法還有別的奧妙?
不過下面這個偏特的寫法倒是比較容易理解:
template <class T>
class Conversion<T,T>
{
public:
    
enum { exists = 1,exists2Way = 1,sameType = 1 };
}
;
這個測試是OK的。

有了這幾個常數,要決定兩個class之間是否存在繼承關系就比較容易了:
#define SUPERSUBCLASS(T,U) \
(Conversion
<const U*const T*>::exists && \
!Conversion<const T*const void*>::sameType)
如果U是public繼承自T,或者T和U是同一個類,那么SUPERSUBCLASS(T,U)傳回true,這里是把某個class視為自己的超類,更嚴謹的做法是:
#define SUPERSUBCLASS_STRICT(T,U) \
(SUPERSUBCLASS(T,U) 
&& \
!Conversion<const T, const U>::sameType)
即排除T與U是同一個類型的情況。

另外,加上 const 是為了 防止因為 const 而導致轉型失敗,對于已經是const的東西再const一次的話后面一次的const會忽略掉。

再,這個宏的名字很清晰,就是 超類--子類, 前面那個T是超類,U是子類,這個命名比 INHERITS要好。

posted @ 2006-02-06 01:11 Tommy Liang 閱讀(471) | 評論 (0)編輯 收藏

就是這樣一個類:
template <class T,class U>
class Conversion
{
    typedef 
char Small;
    
class Big char dummy[2]; };
    
static Small Test(U);
    
static Big Test();
    
static T MakeT();
public:
    
enum { exists = sizeof(Test(MakeT())) == sizeof(Small) };
}
;

關于函數 Small Test(U) 和 Big Test(...) ,書里面說:
。。。需要兩個重載函數,其一如先前所說,接受一個U對象并傳回一個Small對象:
Small Test(U);
但接下來,我該如何寫出一個可接受任何其他種對象的函數呢?。。。。

我覺得這個地方翻譯得有點問題,是不是應該說:“。。我該如何寫出一個可接受任何另外一種類型(即 T)的對象的函數呢。。”,因為這里就是 T和U嘛, 沒有什么“其他種”,這樣翻譯容易讓我迷惑不解了一會兒。

如果接受 U的那個函數被調用,則T可以被轉換為 U,否則無法轉換,這個是思路的根本。

為什么要做一個 MakeT這樣的函數而不直接使用T呢? 這是為了滿足當 T 只有私有構造函數的情況,對于編譯器來說,sizeof 是在編譯期完成評估的,所以,MakeT 里面到底做了什么并不重要,重要的是他返回的類型,是 T,所以,作者很興奮地說,這是一個 StrawMan function,即“稻草人函數”,哈哈,只是一個樣子而已,但是這已經足夠了,那兩個重載的Test方法也是一樣,這里我們不關心他的函數體。強啊,爽歪歪,快感的源泉啊

測試代碼如下:
    using namespace std;

    cout 
<< Conversion<doubleint>::exists << ' '
        
<< Conversion<charchar*>::exists << ' '
        
<< Conversion<size_t, vector<int> >::exists << ' ';
輸出: 1 0 0
double可以轉換為 int
char 不能轉換為 char*
vector<int> 是一個容器的構造函數,size_t 不能轉換,因為這個構造函數是 explicit的,這個地方還是有點迷糊,還得研究一下。

posted @ 2006-02-05 05:34 Tommy Liang 閱讀(787) | 評論 (2)編輯 收藏

簡而言之:explicit修飾的構造函數不能擔任轉換函數

這個 《ANSI/ISO C++ Professional Programmer's Handbook 》是這樣說的

explicit Constructors
A constructor that takes a single argument is, by default, an implicit conversion operator, which converts its argument to
an object of its class (see also Chapter 3, "Operator Overloading"). Examine the following concrete example:
class string
{
private:
int size;
int capacity;
char *buff;
public:
string();
string(int size); // constructor and implicit conversion operator
string(const char *); // constructor and implicit conversion operator
~string();
};
Class string has three constructors: a default constructor, a constructor that takes int, and a constructor that
constructs a string from const char *. The second constructor is used to create an empty string object with an
initial preallocated buffer at the specified size. However, in the case of class string, the automatic conversion is
dubious. Converting an int into a string object doesn't make sense, although this is exactly what this constructor does.

Consider the following:
int main()
{
string s = "hello"; //OK, convert a C-string into a string object
int ns = 0;
s = 1; // 1 oops, programmer intended to write ns = 1,
}
In the expression s= 1;, the programmer simply mistyped the name of the variable ns, typing s instead. Normally,
the compiler detects the incompatible types and issues an error message. However, before ruling it out, the compiler first
searches for a user-defined conversion that allows this expression; indeed, it finds the constructor that takes int.
Consequently, the compiler interprets the expression s= 1; as if the programmer had written
s = string(1);
You might encounter a similar problem when calling a function that takes a string argument. The following example
can either be a cryptic coding style or simply a programmer's typographical error. However, due to the implicit
conversion constructor of class string, it will pass unnoticed:
int f(string s);
int main()
{
f(1); // without a an explicit constructor,
//this call is expanded into: f ( string(1) );
//was that intentional or merely a programmer's typo?
}
'In order to avoid such implicit conversions, a constructor that takes one argument needs to be declared explicit:
class string
{
//...
public:
explicit string(int size); // block implicit conversion
string(const char *); //implicit conversion
~string();
};
An explicit constructor does not behave as an implicit conversion operator, which enables the compiler to catch the
typographical error this time:
int main()
{
string s = "hello"; //OK, convert a C-string into a string object
int ns = 0;
s = 1; // compile time error ; this time the compiler catches the typo
}
Why aren't all constructors automatically declared explicit? Under some conditions, the automatic type conversion is
useful and well behaved. A good example of this is the third constructor of string:
string(const char *);

The implicit type conversion of const char * to a string object enables its users to write the following:
string s;
s = "Hello";
The compiler implicitly transforms this into
string s;
//pseudo C++ code:
s = string ("Hello"); //create a temporary and assign it to s
On the other hand, if you declare this constructor explicit, you have to use explicit type conversion:
class string
{
//...
public:
explicit string(const char *);
};
int main()
{
string s;
s = string("Hello"); //explicit conversion now required
return 0;
}
Extensive amounts of legacy C++ code rely on the implicit conversion of constructors. The C++ Standardization
committee was aware of that. In order to not make existing code break, the implicit conversion was retained. However, a
new keyword, explicit, was introduced to the languageto enable the programmer to block the implicit conversion
when it is undesirable. As a rule, a constructor that can be invoked with a single argument needs to be declared
explicit. When the implicit type conversion is intentional and well behaved, the constructor can be used as an
implicit conversion operator.

posted @ 2006-02-05 05:16 Tommy Liang 閱讀(10036) | 評論 (6)編輯 收藏

睡不著,繼續讀書

有時候,范型程序需要根據一個boolean變量來選擇某個型別或另一個型別。
下面定義的結構提出了解決方案:
template <bool flag,typename T,typename U>
struct Select
{
    typedef T Result;
}
;
//偏特化
template <typename T,typename U>
struct Select<false,T,U>
{
    typedef U Result;
}
;
也就是說,如果flag是true,則編譯器使用第一份定義,即Result被定義為T,
如果是false,則偏特化機制起作用,Result被定義為 U

偏特化真強,全在乎想象力了

posted @ 2006-02-05 04:53 Tommy Liang 閱讀(478) | 評論 (0)編輯 收藏

就是這樣一個結構:

template <typename T>
struct Type2Type
{
    typedef T OriginalType;    
}
;

假定有個片斷如下,創建一個T*
template <class T,class U>
T
* Create(const U& arg)
{
    
return new T(arg);
}

如果對于某個類如“Widget”,其ctor要有兩個參數,比如第二個參數必須是-1(對于舊的代碼來說,誰知道呢:)),但又不想另外創建一個“CreateWidget”方法,那么怎么辦呢,函數是不能偏特化的,即如下代碼:
//錯誤的代碼
template <class U>
Widget
* Create<Widget,U>(const U& arg)
{
    
return new Widget(arg,-1);
}
在 VC7下會報告:非法使用顯式模板參數

只能使用函數重載,比如:
template <class T,class U>
T
* Create(const U&arg,T /*虛擬*/)
{
   
return new T(arg);
}


template 
<class U>
Widget 
* Create(const U& arg, Widget /*虛擬*/)
{
    
return new Widget(arg,-1);
}

  這樣是可以解決問題,但最大的毛病在于運行時構造了 未被使用的對象這個開銷(虛擬的Widget參數)。這時 Type2Type 這個咚咚出場了,按照書的說法,這是“一個型別代表物、一個可以讓你傳給重載函數的輕量級ID”,如下:

template <class T,class U>
T
* Create(const U& arg,Type2Type<T>)
{
    
return new T(arg);
}


template 
<class U>
Widget 
* Create(const U& arg,Type2Type<Widget>)
{
    
return new Widget(arg,-1);
}


調用方:
String 
*pStr = Create("hello",Type2Type<String>());
Widget 
*pW = Create(100,Type2Type<Widget>());

 

關鍵是,這個東西也是給編譯器看的,妙

posted @ 2006-02-05 04:40 Tommy Liang 閱讀(1451) | 評論 (1)編輯 收藏

inline unsigned __int64 GetCycleCount(void)
{
   _asm _emit 
0x0F
   _asm _emit 
0x31
}
dasm如下:
:    inline unsigned __int64 GetCycleCount(void)
7:    {
00401070 55                   push        ebp
00401071 8B EC                mov         ebp,esp
00401073 83 EC 40             sub         esp,40h
00401076 53                   push        ebx
00401077 56                   push        esi
00401078 57                   push        edi
00401079 8D 7D C0             lea         edi,[ebp-40h]
0040107C B9 
10 00 00 00       mov         ecx,10h
00401081 B8 CC CC CC CC       mov         eax,0CCCCCCCCh
00401086 F3 AB                rep stos    dword ptr [edi]
8:       _asm _emit 0x0F
00401088 0F 31                rdtsc
10:   }

0040108A 5F                   pop         edi
0040108B 5E                   pop         esi
0040108C 5B                   pop         ebx
0040108D 
83 C4 40             add         esp,40h
00401090 3B EC                cmp         ebp,esp
00401092 E8 19 00 00 00       call        __chkesp (004010b0)
00401097 8B E5                mov         esp,ebp
00401099 5D                   pop         ebp
0040109A C3                   ret
關鍵就是那個RDTSC指令,即 Read Time Stamp Counter, 結果會保存在EDX:EAX寄存器對中。

Intel的文檔是這樣說的:
With the Pentium processor, Intel added an additional instruction called RDTSC (Read Time Stamp
Counter). This gives software direct access to the number of clock counts the processor has
experienced since its last power
-on or hardware reset. With contemporary clock rates of, for
example, 
3.06 Ghz, that results in a timing period of only 0.326 nanoseconds.

posted @ 2006-02-04 16:40 Tommy Liang 閱讀(252) | 評論 (0)編輯 收藏

僅列出標題
共6頁: 1 2 3 4 5 6 
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美天堂在线观看| 国产日韩精品视频一区| 一本不卡影院| 久久蜜桃资源一区二区老牛| 猫咪成人在线观看| 亚洲第一精品福利| 蜜臀久久99精品久久久久久9 | 欧美国产日韩一区二区三区| 欧美天堂在线观看| 亚洲尤物在线| 久久精品三级| 好吊色欧美一区二区三区视频| 久久五月激情| 99这里只有久久精品视频| 亚洲视频欧美视频| 国产视频久久久久久久| 欧美成年人视频网站欧美| 国产一区香蕉久久| 亚洲精品黄色| 欧美一级在线播放| 激情成人综合网| 欧美日韩国产高清| 久久久久国内| 亚洲性视频h| 亚洲国产欧美在线| 久久久亚洲国产天美传媒修理工| 亚洲精品一区二区三区婷婷月| 国产精品私房写真福利视频| 嫩草国产精品入口| 久久精品国产久精国产爱| 亚洲一区二区三区乱码aⅴ| 欧美国产视频一区二区| 久久精品国产免费观看| 亚洲欧美三级在线| 亚洲一区二区精品视频| 亚洲精品在线电影| 亚洲国产欧美一区二区三区丁香婷| 国产欧美一二三区| 国产精品国产一区二区| 欧美日韩1234| 欧美美女操人视频| 欧美黄色网络| 欧美激情91| 欧美精品手机在线| 欧美大片第1页| 久久在线免费视频| 欧美aⅴ99久久黑人专区| 久久精品麻豆| 久久久久久久综合狠狠综合| 香蕉亚洲视频| 小处雏高清一区二区三区| 亚洲一区日韩| 性欧美暴力猛交69hd| 亚洲免费在线观看视频| 亚洲免费中文字幕| 欧美中文在线视频| 久久手机免费观看| 欧美成人精品| 欧美区在线观看| 欧美日韩一区二区在线视频| 欧美看片网站| 国产精品sm| 国产婷婷精品| 亚洲第一视频网站| 亚洲美女诱惑| 午夜精品视频一区| 久久综合给合| 亚洲国产日韩欧美一区二区三区| 亚洲福利免费| 在线亚洲欧美| 99精品国产一区二区青青牛奶| 亚洲成人在线免费| 这里只有精品视频在线| 久久久久久网址| 亚洲免费在线看| 亚洲欧美变态国产另类| 亚洲综合欧美| 久久精品视频免费| 久久青草久久| 亚洲国产精品黑人久久久| 欧美大片在线观看| 亚洲精品视频中文字幕| 99pao成人国产永久免费视频| 99热精品在线| 亚洲一区二区在线免费观看| 亚洲欧美电影院| 久久精品日韩| 欧美激情第六页| 国产精品美女久久久久久免费| 国产亚洲欧洲997久久综合| 好看的日韩av电影| 一本一本久久| 久久久999精品免费| 亚洲国产一区二区a毛片| 亚洲一区二区精品在线观看| 欧美在线播放| 欧美精品久久久久久久久久| 国产伦精品一区二区三区在线观看 | 一区二区不卡在线视频 午夜欧美不卡在 | 国产日韩精品一区二区三区 | 欧美一区成人| 亚洲三级色网| 久久国产精品第一页| 欧美日韩国产美女| 99re6这里只有精品| 美国三级日本三级久久99| 亚洲精品视频中文字幕| 欧美一区二区视频观看视频| 欧美黑人多人双交| 在线不卡免费欧美| 欧美在线999| 9色国产精品| 欧美经典一区二区| 亚洲国产二区| 久久精品日韩一区二区三区| 中日韩高清电影网| 欧美日韩成人精品| 亚洲国产毛片完整版| 久久免费视频网| 香蕉成人啪国产精品视频综合网| 欧美日韩免费观看中文| 亚洲精美视频| 欧美电影在线| 久久综合电影| 伊人色综合久久天天五月婷| 亚洲欧美日韩国产成人| 一本色道久久精品| 欧美日韩国产免费观看| 99热这里只有成人精品国产| 久久色中文字幕| 久久精品色图| 激情综合视频| 久久综合伊人77777| 欧美与黑人午夜性猛交久久久| 国产视频一区二区三区在线观看| 欧美亚洲在线| 午夜精品亚洲| 国产一区二区三区高清在线观看 | 久久人人看视频| 久久久久天天天天| 亚洲第一视频| 亚洲激情在线播放| 欧美日韩精品免费在线观看视频| av成人免费在线| 一区二区三区四区五区视频| 国产精品免费看片| 久久免费观看视频| 欧美va天堂在线| 国产精品99久久久久久有的能看| 亚洲毛片av在线| 欧美成人精品一区二区| 99国产一区| 亚洲男人av电影| 依依成人综合视频| 亚洲国产毛片完整版| 国产一区二区三区的电影 | 免费影视亚洲| 一本色道久久综合精品竹菊| 一本色道久久综合亚洲精品高清| 国产精品99免费看| 欧美在现视频| 快播亚洲色图| 久久久久一区二区| 麻豆精品在线视频| 亚洲精品你懂的| 日韩一区二区精品| 一本色道久久综合亚洲精品婷婷| 国产精品久久999| 久久久久久日产精品| 欧美日本亚洲视频| 久久精品国产一区二区电影| 久热这里只精品99re8久| 99天天综合性| 欧美一二三区精品| 亚洲精品在线观看免费| 亚洲女与黑人做爰| 亚洲激情一区二区| 欧美在线视频播放| 亚洲一区二区高清| 欧美激情91| 久热国产精品视频| 国产精品三级久久久久久电影| 另类激情亚洲| 欧美不卡视频| 米奇777在线欧美播放| 国产精品丝袜久久久久久app| 欧美不卡视频一区| 欧美先锋影音| 亚洲人成网站777色婷婷| 黄色av一区| 午夜视频在线观看一区二区三区| 一区二区欧美日韩| 欧美大片免费观看在线观看网站推荐| 久久精品色图| 国产欧美日韩精品在线| 一个色综合av| 亚洲欧洲一区二区三区| 狠狠干成人综合网| 午夜在线一区| 欧美一区日韩一区|