Allocation mémoire, je ne comprends pas !
J'ai une fonction qui réalise une allocation mémoire qui est la suivante.
Code:
1 2 3 4 5 6 7 8 9
|
int alloc_matrice_couts(int nbjobs, int** matrice_couts) {
matrice_couts = (int**)malloc(nbjobs * nbjobs * sizeof(int));
if(matrice_couts == NULL){
perror("Erreur d'allocation mémoire (matrice des couts)");
return -1;
}
return 0;
} |
Dans mon programme, je fais appel à cette fonction pour allouer une matrice.
Code:
1 2 3 4 5 6 7 8 9
|
int** matriceCouts;
if(alloc_matrice_couts(cfg.nbJobs, matriceCouts) == -1)
return -1;
/* mise a 0 de la diagonale */
for(i = 0; i < cfg.nbJobs; i++)
matriceCouts[i][i] = 0; // C'est ici que ca plante |
L'allocation a l'air de se passer correctement, mais lorsque j'essai d'accéder aux éléments de ma matrice j'obtient une erreur de segmentation, qu'elle est mon erreur ?
Merci.
Bouba