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

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精品久久久| 香蕉久久夜色精品国产| 亚洲国产精品久久久久| 99视频超级精品| 亚洲女性裸体视频| 久久看片网站| 亚洲国产专区| 在线视频欧美日韩精品| 欧美一区2区视频在线观看| 久久成人综合视频| 欧美大片免费久久精品三p| 国产精品美女一区二区在线观看| 国内精品福利| 国产精品99久久久久久久女警 | 亚洲人成网站在线播| 一本色道久久综合亚洲91| 亚洲一区二区三区免费在线观看| 久久久久欧美| 日韩午夜av电影| 欧美一区二区三区在线观看视频 | 亚洲欧美在线免费观看| 久久阴道视频| 亚洲一区二区视频| 久久视频免费观看| 国产精品日韩欧美大师| 91久久午夜| 久久综合九色99| 亚洲私人影院| 欧美激情第3页| 在线精品亚洲一区二区| 香蕉亚洲视频| 99国产精品久久久| 欧美国产一区在线| 在线成人免费视频| 欧美专区在线观看一区| 中文精品99久久国产香蕉| 女主播福利一区| 国产亚洲精品高潮| 欧美主播一区二区三区美女 久久精品人 | 性18欧美另类| 国产精品美女久久久| 99综合视频| 亚洲日韩中文字幕在线播放| 久久最新视频| 一区二区三区在线观看视频| 欧美在线视频免费| 亚洲一区二区网站| 国产精品国产三级国产| 亚洲特级毛片| 夜夜嗨av色综合久久久综合网| 欧美成人精品福利| 亚洲精一区二区三区| 亚洲高清精品中出| 欧美成人激情视频免费观看| 亚洲国产精品久久91精品| 欧美成人免费全部| 久久久亚洲人| 在线视频观看日韩| 亚洲国产导航| 欧美精品一区二区三区在线看午夜 | 欧美国产另类| 亚洲日本在线观看| 91久久精品国产91性色| 欧美精品一区二区视频| 亚洲欧美不卡| 欧美一区二区成人| 亚洲第一在线综合网站| 亚洲国产精品一区二区www| 欧美jizz19hd性欧美| 9l国产精品久久久久麻豆| 在线亚洲一区二区| 国产亚洲精品aa午夜观看| 麻豆精品视频在线观看视频| 久久久精品国产免大香伊| 亚洲高清色综合| 亚洲美女黄网| 国产午夜精品理论片a级大结局| 久久久久中文| 欧美国产视频在线观看| 亚洲欧美日韩国产综合精品二区| 性欧美办公室18xxxxhd| 日韩网站免费观看| 亚洲欧美高清| 欧美大片18| 最新日韩精品| 亚洲一区二区伦理| 在线免费观看日本欧美| 夜久久久久久| 亚洲国产aⅴ天堂久久| 宅男精品视频| 在线成人性视频| 在线视频欧美精品| 最新亚洲一区| 欧美一区三区二区在线观看| 亚洲午夜激情免费视频| 在线观看一区欧美| 亚洲视屏在线播放| 亚洲人成亚洲人成在线观看 | 久久久亚洲影院你懂的| 亚洲一区二区免费在线| 久久婷婷蜜乳一本欲蜜臀| 亚洲欧美国产日韩中文字幕| 欧美 日韩 国产精品免费观看| 国产精品国内视频| 亚洲福利视频一区二区| 国产亚洲精久久久久久| 在线亚洲一区| 亚洲线精品一区二区三区八戒| 久久欧美中文字幕| 久久久久久网址| 国产精品黄色| 99国产精品私拍| 亚洲欧洲精品天堂一级 | 国产欧美日韩亚州综合| 日韩午夜激情电影| 亚洲精品无人区| 久久精品久久综合| 久久久999精品| 国产精品午夜在线观看| 欧美va天堂va视频va在线| 国产精品一区在线观看你懂的| 亚洲精品久久久久久一区二区| 91久久极品少妇xxxxⅹ软件| 久久精品水蜜桃av综合天堂| 久久精品国产77777蜜臀| 国产精品一二三四区| 亚洲无亚洲人成网站77777| 制服丝袜激情欧洲亚洲| 欧美日韩精品在线视频| 亚洲免费电影在线| 99视频在线精品国自产拍免费观看| 久久美女性网| 欧美激情精品久久久| 亚洲大片av| 欧美电影免费| 一本色道婷婷久久欧美| 亚洲午夜免费视频| 国产精品老牛| 欧美在线视频二区| 免费看亚洲片| 99re66热这里只有精品3直播| 欧美日本不卡高清| 夜夜嗨av一区二区三区四区| 亚洲一品av免费观看| 国产精品欧美风情| 久久riav二区三区| 欧美国产亚洲另类动漫| 一本色道婷婷久久欧美| 国产精品xxxxx| 久久国产精品一区二区| 欧美激情第1页| 在线亚洲伦理| 国产精品爽黄69| 久久男人av资源网站| 亚洲久久一区二区| 欧美一区二区三区婷婷月色 | 99视频热这里只有精品免费| 香蕉久久久久久久av网站| 在线观看中文字幕不卡| 欧美日韩在线视频一区二区| 香蕉成人啪国产精品视频综合网| 久久综合综合久久综合| 日韩一区二区免费看| 国产精品一区=区| 免费成人av资源网| 亚洲欧美日韩精品在线| 亚洲国产精品一区二区www在线| 午夜亚洲视频| 亚洲日韩欧美视频| 国产欧美在线观看一区| 欧美久久久久久久久| 欧美中文在线视频| 亚洲美女av网站| 欧美成年网站| 欧美一区午夜精品| 在线亚洲自拍| 亚洲日韩欧美视频| 精品动漫一区| 国产一区二区丝袜高跟鞋图片| 欧美午夜精品一区| 欧美国产日韩视频| 久久人人97超碰精品888| 午夜精品在线| 亚洲一区二区不卡免费| 亚洲毛片一区二区| 亚洲精品免费一二三区| 亚洲福利一区| 亚洲福利久久|