Page 1 of 1
Free() Function
Posted: Sat Jun 23, 2007 6:29 pm
by Mini
Ok, im not simply asking you to make me the function, im not that n00bish, However, I need help getting in the right direction.
I have search forever for somkind of tutorial on it but cannot find anything on the free function implamentation. I need some help.
Note: Do Not post the code for it as I actualy want to learn about this stuff
Thnx in advance,
~Mini
Posted: Sat Jun 23, 2007 6:38 pm
by t0xic
Mini-
It would help if you explained your malloc() function. Malloc and Free go hand in hand, so not all free()'s are compatible with your malloc function. If you post your malloc() I'm sure you can get your free() worked out.
--t0xic
Posted: Sat Jun 23, 2007 6:44 pm
by Mini
I dont have one yet...
Posted: Sat Jun 23, 2007 7:14 pm
by Kevin McGuire
I can
try to point you in the right direction..
This tutorial shows a lot of the code, but the
alloc function has a bug in it.
Heap Tutorial
Posted: Sat Jun 23, 2007 9:39 pm
by deadmutex
If you go to osdever.net, there's a tutorial that talks about different malloc() and free() implementations. It's called "Dynamic Memory Allocation." Here's a link:
http://www.osdever.net/tutorials.php?cat=6&sort=1
Some of the algorithms that it talks about are: First Fit, Best Fit, and Quick Fit. It has some other interesting stuff as well. (BTW: It has some example code in it)
Posted: Sun Jun 24, 2007 6:29 pm
by Mini
Thanx guy(and gals), Ill check all those out.
Posted: Sun Jun 24, 2007 11:11 pm
by bewing
After a quick look at those references, I think something more is needed.
Doing malloc's requires a clever idea. It takes an AHA! to see how to make it work. Here is one way:
A process requests a buffer of some size. The memory manager allocates the space plus some predefined extra space for a structure. The structure is placed just in front of the "allocated buffer" in memory. The structure contains, perhaps, forward and back pointers to other malloc spaces, maybe some kind of hash code to verify that the control structure doesn't get corrupted by the process ....
When the process calls free(buf), the function takes the pointer and backs it up by the length of the structure -- to access the contents of the control structure, and reincorporate the freed memory into the available memory pool.