victorcoasne
Messages postés1101Date d'inscriptionjeudi 24 avril 2003StatutMembreDernière intervention23 juillet 2023
-
4 août 2007 à 22:23
cs_juju12
Messages postés966Date d'inscriptionsamedi 3 avril 2004StatutMembreDernière intervention 4 mars 2010
-
6 août 2007 à 11:59
Bonjour,
J'ai créé une liste doublement chaînée mais celle-ci contient des erreurs de mémoire.
victorcoasne
Messages postés1101Date d'inscriptionjeudi 24 avril 2003StatutMembreDernière intervention23 juillet 20237 5 août 2007 à 11:38
Bonjour,
Pourquoi dans une fonction ?
Si je veux ajouter plusieurs objets en executant plusieurs fois la fonction ajouté sur action de l'utilisateur autant le laisser en global.
L'erreur c'est un plantage, un bug, une erreur d'exécution lié à une mauvaise gestion de la mémoire.
cs_juju12
Messages postés966Date d'inscriptionsamedi 3 avril 2004StatutMembreDernière intervention 4 mars 20104 5 août 2007 à 18:46
Quand l'élément que tu ajoutes est le dernier (code : if (pPreListViewActu==NULL), vers la fin de AjouteListe), tu as oublié d'initialiser ->pSuivant à 0 donc ça fout le bordel plus tard.
J'ai testé : on dirait que ça marche.
Encore un truc : oublie pas de désalllouer la mémoire des pointeurs (->Colx) dans VideListe() sinon bonjour les fuites.
victorcoasne
Messages postés1101Date d'inscriptionjeudi 24 avril 2003StatutMembreDernière intervention23 juillet 20237 5 août 2007 à 21:46
Bonjour,
Je l'ai refait en class mais problème d'insertion.
Plus de plantage mémoire mais tout les membres insérés ne s'affichent pas !
La messagebox erreur 4 s'affiche mais bizarement pas la 2 !
pPreListViewActu->Col1 = new char[strlen(Colon1)+1];
if (pPreListViewActu->Col1==NULL)
return false;
pPreListViewActu->Col1[0]=0;
strcpy(pPreListViewActu->Col1, Colon1);
pPreListViewActu->Col2 = new char[strlen(Colon2)+1];
if (pPreListViewActu->Col2==NULL)
return false;
pPreListViewActu->Col2[0]=0;
strcpy(pPreListViewActu->Col2, Colon2);
pPreListViewActu->Col3 = new char[strlen(Colon3)+1];
if (pPreListViewActu->Col3==NULL)
return false;
pPreListViewActu->Col3[0]=0;
strcpy(pPreListViewActu->Col3, Colon3);
pPreListViewActu->Col5 = new char[strlen(Colon5)+1];
if (pPreListViewActu->Col5==NULL)
return false;
pPreListViewActu->Col5[0]=0;
strcpy(pPreListViewActu->Col5, Colon5);
/* Ajout de l'entrée */
if (pPreListViewDebut==NULL)
{
pPreListViewDebut = pPreListViewActu;
pPreListViewFin = pPreListViewActu;
}
else
{
PreListView* pPreListViewExplore=pPreListViewDebut;
for (int i=0;pPreListViewExplore!=NULL&&i<NbInsert;i++)
{
if (CompareSystemTime(pPreListViewExplore->Col4, Colon4)<0)
{
pPreListViewActu->pPrecedent = pPreListViewExplore->pPrecedent;
pPreListViewActu->pSuivant = pPreListViewExplore;
if (pPreListViewExplore->pPrecedent != NULL)
pPreListViewExplore->pPrecedent->pSuivant = pPreListViewActu;
else
pPreListViewDebut = pPreListViewActu;
pPreListViewExplore->pPrecedent = pPreListViewActu;
NbInsert++;
return true;
}
pPreListViewExplore = pPreListViewExplore->pSuivant;
if (pPreListViewExplore!=NULL&&i+1>=NbInsert)
{
MessageBox(0, "Erreur grave de gestion de la mémoire !",
"Erreur Interne !", 16);
return false;
}
else if (pPreListViewExplore==NULL&&i+1!=NbInsert)
{
MessageBox(0, "Erreur grave de gestion de la mémoire (3) !",
"Erreur Interne !", 16);
return false;
}
}
pPreListViewFin->pSuivant = pPreListViewActu;
pPreListViewFin = pPreListViewActu;
}
NbInsert++;
return true;
}
inline void Trieur::AfficheListe()
{
PreListView* pPreListViewExplore=pPreListViewDebut;
for (int i=0;pPreListViewExplore!=NULL&&i<NbInsert;i++)
{
cout << pPreListViewExplore->Col1 << pPreListViewExplore->Col2 << pPreListViewExplore->Col3 << pPreListViewExplore->Col5);
pPreListViewExplore = pPreListViewExplore->pSuivant;
if (pPreListViewExplore!=NULL&&i+1>=NbInsert)
{
MessageBox(0, "Erreur grave de gestion de la mémoire (2) !",
"Erreur Interne !", 16);
return;
}
else if (pPreListViewExplore==NULL&&i+1!=NbInsert)
{
MessageBox(0, "Erreur grave de gestion de la mémoire (4) !",
"Erreur Interne !", 16);
return;
}
}
}
Si je met en commentaire :
pPreListViewActu->pPrecedent = pPreListViewExplore->pPrecedent;
pPreListViewActu->pSuivant = pPreListViewExplore;
if (pPreListViewExplore->pPrecedent != NULL)
pPreListViewExplore->pPrecedent->pSuivant = pPreListViewActu;
else
pPreListViewDebut = pPreListViewActu;
pPreListViewExplore->pPrecedent = pPreListViewActu;
NbInsert++;
return true;
là ça marche.
Je précise que CompareSystemTime est une fonction perso qui compare le system time passé en 2ème par rapport en premier et renvoi 1 si supérieur, 0 si égal et -1 si inférieur
cs_juju12
Messages postés966Date d'inscriptionsamedi 3 avril 2004StatutMembreDernière intervention 4 mars 20104 6 août 2007 à 11:59
Ouais mais bon quand la fonction fait une certaine taille (en temps d'exécution) c'est pas les quelques instructions d'appel qui vont retarder beaucoup.