Pointeur sur std::vector casser après un resize()
Bonjour à tous.
J'ai un petit souci avec mon vector.
Petite explication sur le fonctionnement de mon application :
Chaque ligne contiens une structure et j'utilise un pointeur vers celle si depuis des threads.
Avant chaque création de thread je fais un resize() a fin d'ajouter une ligne et d’incorporer une structure.
Le problème est qu’à chaque resize() cela doit modifier l'emplacement mémoire des précédentes lignes et cela casse donc les pointeurs de mes précédents threads.
Quelqu'un aurais une idée de comment contourner ce problème?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| /* .... */
std::vector< thread_data> vectorTelechargement;
/* .... */
pthread_t threads;
int sizeVec = vectorTelechargement.size();
vectorTelechargement.resize(sizeVec+1);
vectorTelechargement[sizeVec].statusDownload = true;
vectorTelechargement[sizeVec].nbThread = 1;
vectorTelechargement[sizeVec].URL = URL.toStdString();
vectorTelechargement[sizeVec].hDlg = (QMainWindow * )ui->pushButtonDownload->parent();
vectorTelechargement[sizeVec].tableViewDownload = (QTableView *)ui->tableViewDownload;
vectorTelechargement[sizeVec].modelTableView = (QStandardItemModel *)model;
pthread_create(&threads, NULL, EnvoieDL, (void *)&vectorTelechargement[sizeVec]); |