Thread: Create malloc and free function in C?

  1. #46
    Registered User
    Join Date
    Jan 2010
    Quote Originally Posted by tabstop View Post
    end is probably the end of the allocated block of memory; but as you say, it is not defined here (nor is it changed here!) so if you want to know what it is you'll have to find it elsewhere.
    Actually I think end is a marker set by the linker (see below) for where the memory occupied by the bootloader code section ends, so everything between &end and MAXBRK is available for use by the allocator.

    Quote Originally Posted by guestcheap View Post
    One problem I had with the script here:i386/boot/cdboot/malloc.c Source is that I have no idea what &end is. It hasn't been declared in this piece of code, so I assume its in boot.h. How do I define end?
    You could, maybe, look at boot.h?
    /* linker stuff */
    extern void end;

  2. #47
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Cambridge, UK
    I'm not quite really sure what OP is upto and from what I can understand after reading the post is either he's trying learn and develop malloc or OS i'm not quite sure. But if its all about creating his own malloc from scratch I say its pretty much starting to develop his OS. But its about memory management like develop your version of malloc with some help OS then there are a few system calls, which you could use to allocate and deallocate. Which effectively what malloc and free does when it gets called. There are system calls like brk and mmap which is used handle memory at the OS level. There is tutorial which I followed while back to understand how malloc actually works. Perhaps worth a read?

    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  3. #48
    Registered User
    Join Date
    Aug 2011

    Thumbs up I've done it.

    It took some time, but I've finally done it.
    Here's the link that helped me out: Creating A Custom Malloc() And Free() In C - C And C++ | Dream.In.Code

    Thanks again to everyone who posted!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. malloc/free help
    By stan4d2012 in forum C Programming
    Replies: 3
    Last Post: 04-13-2009, 07:04 PM
  2. malloc() and free()
    By someprogr in forum C Programming
    Replies: 1
    Last Post: 12-28-2007, 07:16 PM
  3. Malloc - Free giving double free or corruption error
    By andrew.bolster in forum C Programming
    Replies: 2
    Last Post: 11-02-2007, 06:22 AM
  4. need help with malloc-free
    By sleith in forum C Programming
    Replies: 4
    Last Post: 08-22-2007, 08:07 PM
  5. Function to check memory left from malloc and free?
    By Lechx in forum C Programming
    Replies: 4
    Last Post: 04-24-2006, 05:45 AM

Tags for this Thread