I want to know which one is faster: CString or wstring?
I must use wstring in my project which behaves the same way as a CString.
So I created my own MyString class which looks like the one below:
Please don't ask why I must use wstring instead of CString.
#include <string>
using namespace std;
class MyString
{
public:
MyString();
MyString(const wchar_t * pw);
MyString(wchar_t wch);
MyString(const MyString&);
MyString& operator=(const MyString& mstr);
MyString& operator=(const wchar_t* pw);
//~MyString();
bool operator==(const MyString& wstr) const;
wchar_t operator[](size_t pos) const;
bool operator<(const MyString& mstr) const;
friend MyString operator+(const wchar_t* pw, MyString mstr);
MyString operator+(const MyString& mstr);
bool operator!=(const wchar_t* pw);
int Compare(const MyString& mstr) const;
void Append (const MyString& mstr);
size_t Insert(size_t pos, wchar_t wch);
size_t Delete(size_t pos);
size_t Delete(size_t pos, size_t count);
void SetAt(size_t pos, wchar_t wch);
MyString Left(size_t n) const;
MyString Right(size_t n) const;
size_t GetLength() const;
size_t Find(wchar_t wch) const;
MyString Mid(size_t pos) const;
void Empty();
const wchar_t* GetString() const;
const wchar_t* GetBuffer() const;
private:
wstring _word;
};
You can see that this class has the same functions as CString class.
Unfortunatly, I tested this class on my project and it is slower than CString at about 20% and I whonder why is that?
Is it because wstring is slower than CString or because I must define some functions inline?
Please help me!
This is so important to me.
My carrer depends on this, i'm not kidding!
This post has been edited by livium: 20 December 2011 - 03:10 AM

New Topic/Question
Reply


MultiQuote



|