Page 1 of 1

malloc, and other simular functions

Posted: Tue Dec 25, 2007 9:21 am
by PyroMathic
Hi,

I dont have much expirience whit coding in c, but i am trying to build a simple neural network, so a program which require's a lot of memory and which needs to get "free" mem fast.


Now i know malloc is used allot, but how does it work and is it fast? so if for instance i where to call :
malloc(44);

Would malloc then only use up 44 byte's of memory or would it actually use up more then the 44 byte's i asked for?

Also how fast is malloc? or are there other better functions which i could use?

Also is malloc better at finding small ammounts of free memory or better at large ammounts of memory? (small being 32 - 1024 bytes, large 1024++ bytes)


So the general question is: What options do i have when i need free mem in C and what are the good points VS the bad points to these method's.


Regards PyroMathic


BTW: i do know how to build a mem-alloc function in for instance assembly, i just think that, that would be a waste of time...

Posted: Tue Dec 25, 2007 4:50 pm
by Combuster
I have a whole bunch of malloc-related docs on my other computer (which I cannot access until after the holidays) which are quite a good read. Most are scientific papers so I suggest you google for now.
I did get the link to an archive from someone else here, so you might get lucky if that person shows up. :wink:

As a start, you might want to consider to read the doc on DLMalloc, which probably is a close relative of the malloc you're using yourself.
http://g.oswego.edu/dl/html/malloc.html

If you want a algorithm-optimized implementation of memory management functions, you're best off writing your own. DLMalloc itself is however pretty good overall already so you probably wouldn't need to bother with writing one.