Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: thebigred on April 23, 2006, 08:38 PM

Title: Running out of heap memory using malloc
Post by: thebigred on April 23, 2006, 08:38 PM
Edit: I found a much better exercise to garbage collect
Title: Re: Running out of heap memory using malloc
Post by: Kp on April 23, 2006, 09:17 PM
If you're really running out of memory, you've got a leak somewhere.  Run your program through Valgrind (http://www.valgrind.org/) 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.
Title: Re: Running out of heap memory using malloc
Post by: thebigred on April 23, 2006, 09:29 PM
Quote from: Kp on April 23, 2006, 09:17 PM
If you're really running out of memory, you've got a leak somewhere.  Run your program through Valgrind (http://www.valgrind.org/) 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.

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 :(
Title: Re: Running out of heap memory using malloc
Post by: Kp on April 23, 2006, 09:46 PM
Quote from: thebigred on April 23, 2006, 09:29 PMI can't use valgrind...i'm on windows :(

Then it's a good thing that many Linux distributions (http://distrowatch.com/) (such as Debian (http://www.debian.org/), CentOS (http://www.centos.org/), and Ubuntu (http://www.ubuntu.com/)), as well as Valgrind (http://www.valgrind.org/) itself, are Free Software (http://www.gnu.org/philosophy/free-sw.html).  You can fix your Windows problem at no cost.  If you're persistent enough, you might even be able to use a Knoppix (http://www.kernel.org/pub/dist/knoppix/) LiveCD to debug it.  That has the drawback of not decontaminating your hard drive, though.
Title: Re: Running out of heap memory using malloc
Post by: thebigred on April 23, 2006, 10:15 PM
I found a better garbage collection exercise than my book had.
Thanks for the help   :D
Title: Re: Running out of heap memory using malloc
Post by: Zakath on May 04, 2006, 02:14 PM
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.