IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MFC Discussion :

[MFC] Nombre de caractères maximal dans un CString


Sujet :

MFC

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Février 2003
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2003
    Messages : 92
    Points : 55
    Points
    55
    Par défaut [MFC] Nombre de caractères maximal dans un CString
    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,

  2. #2
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    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

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Février 2003
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2003
    Messages : 92
    Points : 55
    Points
    55
    Par défaut
    le nombre max de caractères est donc 512!!

    Peut-on en demander plus?

  4. #4
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    Citation Envoyé par farscape
    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
    non tu as mal lu ,
    la limite de reservation memoire c'est INT_MAX -1 .
    extrait code CString:
    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();
    	}
    }
    c'est plus clair ?

  5. #5
    Membre éclairé
    Avatar de matazz
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    471
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 471
    Points : 668
    Points
    668
    Par défaut
    Mois j'ai réussis à charger un fichier de plusieurs meg dans une seule CString () et ça à plutot bien marché...

  6. #6
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    150
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2004
    Messages : 150
    Points : 180
    Points
    180
    Par défaut
    Juste pour reprendre farscape, INT_MAX = 2,147,483,647
    donc taille maximale de 2Go !

  7. #7
    Rédacteur/Modérateur
    Avatar de Trap D
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    4 942
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 4 942
    Points : 6 498
    Points
    6 498
    Par défaut
    Citation Envoyé par mtopoloff
    Juste pour reprendre farscape, INT_MAX = 2,147,483,647
    donc taille maximale de 2Go !
    Etant prof de math, je te reprends
    INT_MAX = 2 147 483 647

  8. #8
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    150
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2004
    Messages : 150
    Points : 180
    Points
    180
    Par défaut
    Vive les profs de math !

Discussions similaires

  1. [HTML] Nombre de caractères maximal dans un fichier HTML.
    Par ilalaina dans le forum Balisage (X)HTML et validation W3C
    Réponses: 8
    Dernier message: 25/02/2008, 06h41
  2. Nombre de caractères maximum dans un Input Text via method=post ?
    Par dymezac dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 02/11/2007, 23h20
  3. Réponses: 10
    Dernier message: 14/04/2007, 18h57
  4. Réponses: 28
    Dernier message: 11/10/2006, 22h36
  5. Problème de nombre de caractères max dans Listbox
    Par jojoestpetit dans le forum Access
    Réponses: 1
    Dernier message: 09/04/2006, 11h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo