need help wit sbrk

Discussion in 'C++' started by J de Boyne Pollard, Sep 12, 2007.

  1. h> Now the next step is to write malloc and free, for kernel
    h> heap management. I am keeping my kernel heap at
    h> 0XD0000000. My understanding is that malloc calls sbrk
    h> to allocate more memory to the heap. [...]

    Your understanding is wrong. You're doing kernel-mode programming.
    Throw out your applications-mode programming assumptions. They
    aren't, in this particular instance, even suitable for applications-
    mode. (The concept underpinning sbrk() is about 30 years out of
    date. It was out of date in 1988, when it was excluded from POSIX
    1003.1.) malloc() calls whatever you implement it as calling.

    To implement a simple malloc()/free()/new/delete, you need three
    things: a list of heaps, a heap creator/destroyer to create and
    destroy those heaps on demand, and a heap sub-allocator/deallocator to
    allocate and free memory from within individual heaps. In
    applications mode, these are often provided as standard operating
    system functions. Witness DosAllocMem()/DosFreeMem()/DosSubSetMem()
    and DosSubAllocMem()/DosSubFreeMem() on OS/2, and HeapAlloc()/
    HeapDestroy() and HeapAlloc()/HeapFree() on Win32. For kernel-mode
    programming, you need to implement something akin to these yourself.
    You say that you have a facility for allocating and freeing 1 or more
    whole pages. You thus have the necessary equivalents to DosAllocMem()
    and DosFreeMem() already.
    J de Boyne Pollard, Sep 12, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kris Rockwell

    Problems wit Databinding to a DropDown box

    Kris Rockwell, Apr 4, 2004, in forum: ASP .Net
    Replies:
    8
    Views:
    383
    Kris Rockwell
    Apr 6, 2004
  2. chessc4c6
    Replies:
    9
    Views:
    461
    Old Wolf
    Mar 8, 2005
  3. Malloc & sbrk

    , Mar 5, 2006, in forum: C Programming
    Replies:
    6
    Views:
    1,016
    Keith Thompson
    Mar 6, 2006
  4. venkat

    Regarding brk and sbrk

    venkat, Oct 17, 2007, in forum: C Programming
    Replies:
    12
    Views:
    1,468
    CBFalconer
    Oct 25, 2007
  5. Replies:
    8
    Views:
    305
    JosephKK
    May 6, 2009
Loading...

Share This Page