Bonjour,
Y a t'il une limite du nombre de caractères pour un CString?
Et si oui, peut-on definir cette valeur maximale?
Merci,
Bonjour,
Y a t'il une limite du nombre de caractères pour un CString?
Et si oui, peut-on definir cette valeur maximale?
Merci,
salut,
la classe CString fait un new pour les longueurs > 512 ,
la limite testée est que la longueur demandée soit <= INT_MAX -1
le nombre max de caractères est donc 512!!
Peut-on en demander plus?
non tu as mal lu ,Envoyé par farscape
la limite de reservation memoire c'est INT_MAX -1 .
extrait code CString:
c'est plus clair ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 void CString::AllocBuffer(int nLen) // always allocate one extra character for '\0' termination // assumes [optimistically] that data length will equal allocation length { ASSERT(nLen >= 0); ASSERT(nLen <= INT_MAX-1); // max size (enough room for 1 extra) if (nLen == 0) Init(); else { CStringData* pData; #ifndef _DEBUG if (nLen <= 64) { pData = (CStringData*)_afxAlloc64.Alloc(); pData->nAllocLength = 64; } else if (nLen <= 128) { pData = (CStringData*)_afxAlloc128.Alloc(); pData->nAllocLength = 128; } else if (nLen <= 256) { pData = (CStringData*)_afxAlloc256.Alloc(); pData->nAllocLength = 256; } else if (nLen <= 512) { pData = (CStringData*)_afxAlloc512.Alloc(); pData->nAllocLength = 512; } else #endif { pData = (CStringData*) new BYTE[sizeof(CStringData) + (nLen+1)*sizeof(TCHAR)]; pData->nAllocLength = nLen; } pData->nRefs = 1; pData->data()[nLen] = '\0'; pData->nDataLength = nLen; m_pchData = pData->data(); } }
Mois j'ai réussis à charger un fichier de plusieurs meg dans une seule CString () et ça à plutot bien marché...
Juste pour reprendre farscape, INT_MAX = 2,147,483,647
donc taille maximale de 2Go !
Etant prof de math, je te reprendsEnvoyé par mtopoloff
INT_MAX = 2 147 483 647
Vive les profs de math !
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager