• Welcome to Valhalla Legends Archive.
 

Running out of heap memory using malloc

Started by thebigred, April 23, 2006, 08:38 PM

Previous topic - Next topic

thebigred

Edit: I found a much better exercise to garbage collect

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.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

thebigred

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 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 :(

Kp

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 (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.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

thebigred

#4
I found a better garbage collection exercise than my book had.
Thanks for the help   :D

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.
Quote from: iago on February 02, 2005, 03:07 PM
Yes, you can't have everybody...contributing to the main source repository.  That would be stupid and create chaos.

Opensource projects...would be dumb.