Free() Function

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Mini
Posts: 18
Joined: Mon Apr 30, 2007 6:29 pm
Contact:

Free() Function

Post 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
===RygnorkOS Progress===
Version:ALPHA BETA, 0.0.1
Currently working on: getting bootloader to actually work >:(
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post 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
Mini
Posts: 18
Joined: Mon Apr 30, 2007 6:29 pm
Contact:

Post by Mini »

I dont have one yet...
===RygnorkOS Progress===
Version:ALPHA BETA, 0.0.1
Currently working on: getting bootloader to actually work >:(
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Post 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
User avatar
deadmutex
Member
Member
Posts: 85
Joined: Wed Sep 28, 2005 11:00 pm

Post 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)
Mini
Posts: 18
Joined: Mon Apr 30, 2007 6:29 pm
Contact:

Post by Mini »

Thanx guy(and gals), Ill check all those out.
===RygnorkOS Progress===
Version:ALPHA BETA, 0.0.1
Currently working on: getting bootloader to actually work >:(
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post 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.
Post Reply