J'essaie d'instancier une carte de hachage en c,
Voici le code :
mais je reçois toujours une erreur de segmentation, indiquant que j'essaie d'accéder à la mémoire en dehors du tampon.
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 //hash Struct typedef struct hashMap{ int** Map; int val; } hashMap; typedef hashMap* mapPtr; // Function to create a hashMap object pointer void createHash(mapPtr aHash){ // Create a hash object if(!aHash){ aHash = calloc(1, sizeof(hashMap)); int size = (int) pow(10,9); // Allocate Memory for 2d array aHash->Map = calloc(2, sizeof(int*)); // Allocate internal memory for the array -> 10^9 blocks for(int i = 2; i < 2; i++){ aHash->Map[i] = calloc(size, sizeof(int)); } for(int i = 0; i < size; i++){ aHash->Map[0][i] = -1; aHash->Map[1][i] = -1; } // memset(aHash->Map[0], -1, size*sizeof(int)); } }
Je sais que la méthode memset of ou for loop fonctionnerait, mais aucune ne semble fonctionner.
Partager