I am sorry if the question is stupid. The problem is that memory for my dynamic array inside a static structure is not being allocated. The reason might be my pc (it is a really old notebook with only 8 gbs of RAM) but I doubt it is.I propably done a mistake while coding allocation of memory to the
I have the following structs with static values
struct City {
std::string name;
int Population=0;
bool HasMetro=false;
}NullCity;
struct HashNode {
long long key=0;
City data;
};
HashNode NullNode = {0,NullCity};
struct LinkedList {
HashNode Data;
LinkedList* next=nullptr;
};
LinkedList NullList = {NullNode, nullptr};
struct HashTable {
int size=0;
LinkedList** BucketsArray;
int amount=0;
};
HashTable HT={30,new LinkedList*[30],0};
The code before was aimed at HT.BucketsArray to be a fixed and I am slowly trying to make it dynamic array.
But when I innitialise the code instead of giving me an array of null pointers as it gave me while it was a fixed array it gives me this
@ ALREADY PREPROCESSED @HT = {HashTable}
size = {int} 30
BucketsArray = {LinkedList **} 0xef3b00
*BucketsArray = {LinkedList *} 0xbaadf00dbaadf00d
*value = {LinkedList}
error = Error occurred in Python: Cannot access memory at address 0xbaadf00dbaadf03d
amount = {int} 0
((Also I am coding in Clion c++ not in python so I am suprised to see it here)) To note is was as follows before
@ ALREADY PREPROCESSED @HT = {HashTable}
size = {int} 30
BucketsArray = {LinkedList *[30]}
[0] = {LinkedList *} NULL
[1] = {LinkedList *} NULL
[2] = {LinkedList *} NULL
[3] = {LinkedList *} NULL
[4] = {LinkedList *} NULL
[5] = {LinkedList *} NULL
[6] = {LinkedList *} NULL
[7] = {LinkedList *} NULL
[8] = {LinkedList *} NULL
[9] = {LinkedList *} NULL
[10] = {LinkedList *} NULL
[11] = {LinkedList *} NULL
[12] = {LinkedList *} NULL
[13] = {LinkedList *} NULL
[14] = {LinkedList *} NULL
[15] = {LinkedList *} NULL
[16] = {LinkedList *} NULL
[17] = {LinkedList *} NULL
[18] = {LinkedList *} NULL
[19] = {LinkedList *} NULL
[20] = {LinkedList *} NULL
[21] = {LinkedList *} NULL
[22] = {LinkedList *} NULL
[23] = {LinkedList *} NULL
[24] = {LinkedList *} NULL
[25] = {LinkedList *} NULL
[26] = {LinkedList *} NULL
[27] = {LinkedList *} NULL
[28] = {LinkedList *} NULL
[29] = {LinkedList *} NULL
amount = {int} 0
((Both current output and output from before are taken from Clion Debuger at the start of the int main() function.))
I also tried to declare HT the following ways and none of them gave me memory.
struct HashTable {
int size=30;
LinkedList** BucketsArray = new LinkedList*[size];
int amount=0;
};
HashTable HT;
struct HashTable {
int size=30;
LinkedList** BucketsArray = new LinkedList*[30];
int amount=0;
};
HashTable HT;
struct HashTable {
int size=0;
LinkedList** BucketsArray;
int amount=0;
};
HashTable HT={};
LinkedList** BucketsArray;- Why? Why manual memory management? Why not just use one of the standard containers? Strive to be a "zero star programmer" when you can.LinkedLists is spelled:std::vector<LinkedList*>#includes and amain()that exercises just one thing, so we can see exactly what's expected.<list>exists and assuming some kind of homework. Hash tables as a linked list also makes little sense. The point is to use the hash for O(1) access to your data, linked list means your access time is O(n) due to needing to iterate the list.