Find the answer to your Linux question:
Results 1 to 4 of 4
In C, when you call malloc(), calloc() etc the memory it reserves is on the heap, and not on the stack. Im trying to learn a bit of assembly at ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Guru
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    3,284

    Heap memory in Assembly


    In C, when you call malloc(), calloc() etc the memory it reserves is on the heap, and not on the stack. Im trying to learn a bit of assembly at the moment, but cannot find any docs or tutorials that talk specifically about memory management issues, and how to access the heap etc.

    Any pointers / links?

    Ta,

    Jason

  2. #2
    Linux Enthusiast scientica's Avatar
    Join Date
    Sep 2003
    Location
    South- or "Mid-" Sweden
    Posts
    742
    Ah, allocating space from the stack, the greast joy of all ...
    simply: substract the amount you need from esp, and the add them back when done.
    realaity: "a few" things to think of, like alignment, the calls you make (as they modify the stack, sure using ebp and esp "propperly" will make things easier, but still).
    If it's more than a few dwords you'll only be using for the life time of a procedure then I'd recomend that you use malloc(), since playing with the stack can be hazardous - if you got bad luck you'll creash you app (or in a fancier wording "render undefined behaviour") - you might end up calling another function when you planned to return from another.

    I'll see if I can find any nice tuts, iirc I saw some att linuxassembly.org.
    Regards Scienitca (registered user #335819 - http://counter.li.org )
    --
    A master is nothing more than a student who knows something of which he can teach to other students.

  3. #3
    Linux Guru
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    3,284
    cheers, i've checked out linuxassembly already.

    What i was after more is info about memory NOT on the stack, but on the HEAP.

    Any ideas?

    Ta,

    Jason

  4. #4
    Just Joined!
    Join Date
    May 2004
    Location
    Oxford, UK
    Posts
    15
    brk() system call modifies the size of the heap directly, you need to know how to issue system calls from assembly

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •