Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory allocation problem in HashTable
    text
    copied!<p><strong><em>Please don't close this saying a <a href="https://stackoverflow.com/questions/827986/why-this-code-doesnt-allocate-memory-in-c-please-help">duplicate question</a>. I made an important change so not to confuse people, I resubmitted this much clearer codes.</em></strong></p> <p>Please help me to solve this memory allocation problem. I'm working on a HashTable and this is what I've (partial codes only)</p> <p><strong>main.c</strong></p> <pre><code>HashTablePtr hash; hash = createHashTable(10); insert(hash, "hello"); insert(hash, "world"); </code></pre> <p><strong>HashTable.c</strong></p> <pre><code> HashTablePtr createHashTable(unsigned int capacity){ HashTablePtr hash; hash = (HashTablePtr) malloc(sizeof(HashTablePtr)); hash-&gt;size = 0; hash-&gt;capacity = capacity; hash-&gt;list = (ListPtr *)calloc(capacity, sizeof(List)); /*NO MEMORY ALLOCATION HERE*/ return hash; </code></pre> <p><strong>List.h</strong></p> <pre><code>typedef struct list List; typedef struct list * ListPtr; struct list { int size; NodePtr head; NodePtr tail; }; ... ... </code></pre> <p><strong>HashTable.h</strong></p> <pre><code> typedef struct hashtable * HashTablePtr; typedef struct hashtable HashTable; struct hashtable { unsigned int capacity; unsigned int size; ListPtr *list; unsigned int (*makeHash)(unsigned int, void *); }; ... ... </code></pre> <p>When I run my debugger (Netbeans C/C++ debugger, I see no memory being allocated to hash->list. In above example, my attempt is to make it an array of 10 lists.</p> <p>Please help me to solve this.</p> <p>I'm not that expert in C, if that helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload