私は入力パラメータ(通常512文字未満(ユニコード)以下)で数百万個のchar *を取り込む必要があるアプリケーションを持っています。ネット文字列。数百万のchar *を文字列変換に最適化
私のアプリケーションのパフォーマンスは、実際のボトルネックになります。私はそれがより効果的になるようなデザインパターンやアイデアがあるのだろうかと思っています。
私はそれが改善されるように感じさせる重要な部分があります:重複がたくさんあります。 100万のオブジェクトが入ってきているとすれば、50個の一意のchar *パターンのようにしか見えません。レコードの
は、ここで私は、文字列へのchar *に変換するために使用しているアルゴリズム(このアルゴリズムはC++であるが、プロジェクトの残りの部分はC#である)私はおそらく使用する
String ^StringTools::MbCharToStr (const char *Source)
{
String ^str;
if((Source == NULL) || (Source[0] == '\0'))
{
str = gcnew String("");
}
else
{
// Find the number of UTF-16 characters needed to hold the
// converted UTF-8 string, and allocate a buffer for them.
const size_t max_strsize = 2048;
int wstr_size = MultiByteToWideChar (CP_UTF8, 0L, Source, -1, NULL, 0);
if (wstr_size < max_strsize)
{
// Save the malloc/free overhead if it's a reasonable size.
// Plus, KJN was having fits with exceptions within exception logging due
// to a corrupted heap.
wchar_t wstr[max_strsize];
(void) MultiByteToWideChar (CP_UTF8, 0L, Source, -1, wstr, (int) wstr_size);
str = gcnew String (wstr);
}
else
{
wchar_t *wstr = (wchar_t *)calloc (wstr_size, sizeof(wchar_t));
if (wstr == NULL)
throw gcnew PCSException (__FILE__, __LINE__, PCS_INSUF_MEMORY, MSG_SEVERE);
// Convert the UTF-8 string into the UTF-16 buffer, construct the
// result String from the UTF-16 buffer, and then free the buffer.
(void) MultiByteToWideChar (CP_UTF8, 0L, Source, -1, wstr, (int) wstr_size);
str = gcnew String (wstr);
free (wstr);
}
}
return str;
}
C++ではなく、C++/CLIやC++/CXのようです。タグが変わっていないのは、どちらがわからないからです。 – bames53
あなたは50個ほどのC#文字列とその100万回の参照で終わりたいのですか? –
C++/CLIです。はい、100万回の参照があります。 – greggorob64