Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7433343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:39:16+00:00 2026-05-29T09:39:16+00:00

how do you manually manage the heap in mips assembly, specifically the SPIM simulator?

  • 0

how do you manually manage the heap in mips assembly, specifically the SPIM simulator?

the heap, i’ve found begins at 0x10040000 when using the sbrk syscall, e.g.

li $t0, 1

li $s0, 9

syscall

sw $t0, ($s0) # 1 located at 0x10040000

so, does a call to sbrk NOT guarantee that you will get back the next free memory slot? for instance, if i called sbrk for a single 4 byte space, SPIM might allocate addresses: 0x10040000-0x10040003. however, a second call for another 4 byte space might be unrelated to the prior 4 byte allocation? thus, a data structure is required to keep track of which memory slots have been allocated? finally, do memory managers try to reduce the number of calls to sbrk by determining free space that lies between the addresses that are tracked by the particular data structure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:39:17+00:00Added an answer on May 29, 2026 at 9:39 am

    On real systems, sbrk returns page-granularity allocations. I’m not sure if the SPIM simulator does (the meagre online docs imply it will return any byte-oriented granularity).

    Generally, the sbrk system call just sets the “end-of-heap” pointer. All the underlying OS knows is the beginning of the heap (where sbrk started at the beginning of the program), and the current end-of-heap pointer. All the memory in that bound is considered (from the OS point of view) heap memory in use by the program.

    (Note, in your case I believe the SPIM simulator takes an integer to bump the pointer by, so implicitly all the memory is contiguous and I think the break is always increasing?)

    The “malloc” API that is generally built on sbrk provides more than a simple contiguous, growing memory region. A good malloc library generally lets you mark a region of memory as “free” (so it can be used to satisfy a subsequent malloc call). Note that OS generally doesn’t know about this “free”. Malloc keeps track of the memory that is free or not. In general malloc cannot return this arbitrary region of the heap to the OS, because the heap is a single contiguous region from the OS point of view.

    Real malloc implementations have to deal with the mis-match between allocation requests and page-size (normal sbrk only returns multiples of page-aligned, page-sized allocations). Your simulator case doesn’t have this problem because sbrk is fine-grained.

    Note that tracking which memory is in use or not requires memory, so malloc has some overhead. Some implementations are designed to store most of this bookkeeping in the “free” memory (reducing the apparent cost to the client). There are lots of other strategies for matching malloc to sbrk…. (In your case mapping malloc to sbrk, and making free a no-op will ‘work’ as long as you don’t allocate too much memory …)

    Here’s an overview of how malloc and sbrk relate that draws some ASCII art I don’t have the patience to transcribe: http://web.eecs.utk.edu/~huangj/cs360/360/notes/Malloc1/lecture.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going to manually manage the memory of the NSMutableDictionay, without using autorelease. And
I'm trying to manually manage some geometry (spatial) columns in a rails model. When
I have a DataGridView where I manage manually the focused cells when navigating with
I have a project I'm looking to manually manage via perforce version control as
Is it necessary to manually manage the lifetime of System.Drawing objects? Currently I am
I'm currently using Subversion to manage my ASP.NET website. I'm finding that whenever I
I'm using an NSFetchedResultsController to populate and manage my tables data source. When a
We are using CMake to manage our builds and have a rather large project
I am tired of having to manage projects manually. We use subversion for version
I manage an online catalog. Currently in-house personnel update it manually, and their changes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.