Valhalla Legends Forums Archive | C/C++ Programming | Running out of heap memory using malloc

AuthorMessageTime
thebigred
Edit: I found a much better exercise to garbage collect
April 24, 2006, 1:38 AM
Kp
If you're really running out of memory, you've got a leak somewhere.  Run your program through Valgrind to find the leak(s).  It looks like you're leaking whenever you run Resize_Hash_Table.

A few remarks on your code in general:

Why're you declaring malloc manually (and redeclaring it in every function that uses it!)?  Just include stdlib.h.

Why're you writing a hash table by hand?  Unless this is for experience or for an assignment, you should use a proven implementation.
April 24, 2006, 2:17 AM
thebigred
[quote author=Kp link=topic=14836.msg151167#msg151167 date=1145845072]
If you're really running out of memory, you've got a leak somewhere.  Run your program through Valgrind to find the leak(s).  It looks like you're leaking whenever you run Resize_Hash_Table.

A few remarks on your code in general:

Why're you declaring malloc manually (and redeclaring it in every function that uses it!)?  Just include stdlib.h.

Why're you writing a hash table by hand?  Unless this is for experience or for an assignment, you should use a proven implementation.
[/quote]

I was recommended using hash tables to learn how to allocate the heap.  I was using the default hashtable for my javaop clan list, but manual control with C is quite powerful so I thought this would help in the future.

I can't use valgrind...i'm on windows :(
April 24, 2006, 2:29 AM
Kp
[quote author=thebigred link=topic=14836.msg151172#msg151172 date=1145845761]I can't use valgrind...i'm on windows :([/quote]

Then it's a good thing that many Linux distributions (such as Debian, CentOS, and Ubuntu), as well as Valgrind itself, are Free Software.  You can fix your Windows problem at no cost.  If you're persistent enough, you might even be able to use a Knoppix LiveCD to debug it.  That has the drawback of not decontaminating your hard drive, though.
April 24, 2006, 2:46 AM
thebigred
I found a better garbage collection exercise than my book had.
Thanks for the help  :D
April 24, 2006, 3:15 AM
Zakath
Please don't remove the details of your question when it is resolved. By doing this, you've eliminated the possibility of others benefiting by reading this thread.
May 4, 2006, 7:14 PM

Search