Thread: Writing my own malloc.

  1. #31
    Registered User
    Join Date
    Oct 2007
    Posts
    242
    Yep, thanks, I've got the idea that only the OS itself can only access this part of the memory.

  2. #32
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by eXeCuTeR View Post
    Yep, thanks, I've got the idea that only the OS itself can only access this part of the memory.
    Not sure you completely understand how things work. There are many different ways that we COULD implement a memory pool manager (which malloc/free traditionally provides some of the functions to use). The concept is rather simple: We get a big block of memory, and split it into smaller portions, marking those portions as "in use", and when freeing, you record the freed memory as "not in use".

    How you get that memory depends on the OS implementation. Generally, the OS manages some sort of basic "big block" methods that work on the same principle as malloc & free, but are more suitable when allocating kilobytes or megabytes, rather than a few dozen bytes.

    The application itself can not get more memory without asking the OS to get it. This is where the "big block memory allocation" comes in handy. In windows, that would normally be the HeapAlloc() function, but there are several others [but those have specific functionality/restrictions that isn't ideal if you want to implement malloc()].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Malloc for extending the size....!
    By patil.vishwa in forum C Programming
    Replies: 5
    Last Post: 09-11-2008, 03:34 AM
  2. the basics of malloc
    By nakedBallerina in forum C Programming
    Replies: 21
    Last Post: 05-20-2008, 02:32 AM
  3. A bug I cannot see. . . malloc issue
    By Kennedy in forum C Programming
    Replies: 16
    Last Post: 09-26-2007, 09:49 AM
  4. Alternative to malloc
    By stellastarr in forum C Programming
    Replies: 13
    Last Post: 04-30-2007, 04:10 PM
  5. help with malloc
    By geetee in forum C Programming
    Replies: 1
    Last Post: 10-23-2001, 12:07 PM