Ho un'applicazione che deve contenere diversi milioni di caratteri * come parametro di input (in genere stringhe inferiori a 512 caratteri (in unicode)) e convertirli e memorizzarli come. stringhe nette.Ottimizzazione di diversi milioni di caratteri * per conversioni di stringhe
Si sta rivelando un vero e proprio collo di bottiglia nelle prestazioni della mia applicazione. Mi chiedo se c'è qualche schema di progettazione o idee per renderlo più efficiente.
C'è una parte fondamentale che mi fa sentire come può essere migliorata: ci sono un sacco di duplicati. Dici che arrivano 1 milione di oggetti, potrebbero esserci solo 50 modelli char * unici.
Per la cronaca, ecco l'algoritmo che sto utilizzando per convertire char * a stringa (questo algoritmo è in C++, ma il resto del progetto è in 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;
}
Sembra C++/CLI o C++/CX anziché C++. Non sto cambiando il tag solo perché non so quale. – bames53
Quindi vuoi finire con solo le tue 50 stringhe C# e un milione di riferimenti? –
C++/CLI e sì, potrei avere 1 milione di riferimenti, è una raccolta di test nel tempo. – greggorob64