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

  • SEARCH
  • Home
  • 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 7398369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:51:41+00:00 2026-05-29T03:51:41+00:00

I am working an OS program and I am trying to figure out how

  • 0

I am working an OS program and I am trying to figure out how malloc works pertaining to the stack. When a user calls malloc, is the pointer returned from malloc at the top of the stack and after the given space or at the bottom of the given space?

If I am loading variables into this new space using assembly code, and it isn’t enough to fill the whole space, should the variables be pushed in at the beginning of the freed space, or pushed to the point where the last variable would take up the last amount of free space given from malloc?

Thanks.

  • 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-29T03:51:42+00:00Added an answer on May 29, 2026 at 3:51 am

    The whole point of malloc is to not allocate from the stack, but from the heap. If you want to allocate from the stack, you’d use alloca.

    If you allocate on the stack and leave your current stack frame (that is, you return from the function) then the previously stack-allocated stuff might (in most situations: will) be overwritten by a different function call later on. So this obviously is not the place for “long-term” storage. For data that need to live longer than a function call, you need to allocate from the heap. That’s what malloc does.

    How malloc is doing its work depends on the OS features available and the implementation. See the question: How do malloc() and free() work?.

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

Sidebar

Related Questions

I am working on a drawing program and am trying to figure out the
I am working on my first NASM program, and while trying to figure out
I am trying to figure out why a program I am working on goes
I was trying to figure out how much memory I can malloc to maximum
I am working on a homework assignment and I'm trying to figure out a
I'm new to Java, and trying to figure out how to structure my program's
Hello I am writing this program, and I am trying to figure out how
I have a problem I cant seem to figure out. Working in Django trying
I am using Junit 4. My whole program is working fine. I am trying
I am working through trying to learn to program in Python and am focused

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.