Thread: implementation our own malloc implementation with out using predefined malloc routine

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    1

    implementation our own malloc implementation with out using predefined malloc routine

    I'm developing an memory manager module based on buckets of fixed size memory blocks n can do the operations such as malloc free and realloc...but i dont know how to write the code to implement our own malloc...any one could help me...if so I'm very grateful to them

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    What you have asked, does not make sense. You mentioned you can do it, then you can't?

    If you have a "fixed" block of memory, then there are few techniques to "allocate" and keep track of memory within this block.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    char pool[1000000];
    Now write your malloc/free which chops pool up into smaller blocks, hands them out to malloc, and reclaims them on free.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    What platform?
    Mainframe assembler programmer by trade. C coder when I can.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    If you specify the compiler, I can tell you the command that will disclude the built-in malloc(). Though I am wondering if that is what you are asking, or if you are simply asking how to write your own malloc().

    My usual line of thinking is the same as if someone were to ask me to move out of my desk at work: I was here first, so why should I change? That said, why should you get rid of the standard C function since it was there first? Just name yours something else. Plus sometimes for debugging purposes this is the only way to know for sure if your code is broken, or your memory manager is broken.

  6. #6
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    I can think of lots of reasons to write your own memory managers. I need to write one now myself for what I'm doing.

    The OP is asking "can do the operations such as malloc free and realloc" and not necessarily overriding those with like-named ones.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I think the OP is a one post wonder. I know Salem will hound his ass around the net looking for every other site where he asked this same question.

  8. #8
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Heh. Coolness.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM