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
Free() Function
Free() Function
===RygnorkOS Progress===
Version:ALPHA BETA, 0.0.1
Currently working on: getting bootloader to actually work >:(
Version:ALPHA BETA, 0.0.1
Currently working on: getting bootloader to actually work >:(
- Kevin McGuire
- Member
- Posts: 843
- Joined: Tue Nov 09, 2004 12:00 am
- Location: United States
- Contact:
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
This tutorial shows a lot of the code, but the alloc function has a bug in it.
Heap Tutorial
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)
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)
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.
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.