Like Tree16Likes

Create malloc and free function in C?

This is a discussion on Create malloc and free function in C? within the C Programming forums, part of the General Programming Boards category; Originally Posted by tabstop end is probably the end of the allocated block of memory; but as you say, it ...

  1. #46
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    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?
    Code:
    /* linker stuff */
    extern void end;
    Salem likes this.

  2. #47
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    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?

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

  3. #48
    Registered User
    Join Date
    Aug 2011
    Posts
    10

    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!

Page 4 of 4 FirstFirst 1234
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, 08: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, 07:22 AM
  4. need help with malloc-free
    By sleith in forum C Programming
    Replies: 4
    Last Post: 08-22-2007, 09: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, 06:45 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21