06 Feb, 2011, JohnnyStarr wrote in the 21st comment:
Votes: 0
Not a bug really. I had planned on doing that very thing. But I wanted to make sure my approach was
even sound before addressing every detail. Thanks for the tip on memset(), very cool. I'm going to take
some time learning the ins-and-outs of the C libraries.

Another concern is struct initialization. Would it make sense to have a *_new() function and a *_init()
to separate the the memory allocation from initialization. In other words, I may not always need to allocate
the PHash on the heap. For instance, would it be right to have a local struct variable and send it to the
PHash library functions via that & operator?

EG:

PHash h;
pgH_insert(&h, "{g", "green");

/* def of pgH_insert */
void pgH_insert(PHash* h, char*k, char*v);
06 Feb, 2011, David Haley wrote in the 22nd comment:
Votes: 0
You would separate the 'new' and 'init' if there are several ways of creating the structure. If you do foresee recycling of data structures, then yes, you would split the two. But note that that's complicated, and you have a lot of extra stuff to keep track of (like uninitializing the old data structure first). Honestly, for a hash table, I think you should have single allocation followed by destruction and that's it…
07 Feb, 2011, JohnnyStarr wrote in the 23rd comment:
Votes: 0
The signature of memset is memset(void*, int, size_t);
int being the assignment argument. how would that work with allocation using an array of struct pointers?
07 Feb, 2011, David Haley wrote in the 24th comment:
Votes: 0
What do you mean? The array is just a chunk of bytes; you'll want to set each of those bytes to zero.
08 Feb, 2011, JohnnyStarr wrote in the 25th comment:
Votes: 0
will that de-allocate the pointers?
08 Feb, 2011, Runter wrote in the 26th comment:
Votes: 0
No, the only way to "deallocate" memory is by calling free.

int *arr[10]; // 10 int pointers
memset(arr, 0, sizeof(int*) * 10); // all pointers zero'd
09 Feb, 2011, JohnnyStarr wrote in the 27th comment:
Votes: 0
gotcha, thanks :)
20.0/27