answersLogoWhite

0


Best Answer

Stack memory is memory assigned to a task or other instruction loop that it uses to perform instructions. Stack is used any time variables are declared inline with the code (see example below). Stack is also used for preserving registers whenever the processor switches contexts (from task to interrupt, between interrupts, or between tasks).

Stack is provide either by the Operating System when the task is started, statically when a task is defined (as would be in an RTOS), or at compile time if there is no operating system. In the third case, the stacks in the system are assigned for each of the various interrupt contexts and the main loop.

Stack usage example:

void somefunc(int a)

{

// "int a" will be in a CPU register

int i=0; // May be either a CPU register or on the stack, depending on CPU architecture and compiler.

char c[10]; // Will exist on the stack

struct somestruct *ss=malloc(sizeof(struct somestruct));

// The memory that ss points to will be in the "heap", the pointer to this memory will be on the stack.

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What section of memory is used to make stack?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Stack register are used to store?

The stack register contains the address of the last item pushed on the stack. The stack is a region of memory used for temporary storage of instruction addresses and register values in a Last-In-First-Out (nested) structure. It is used for interrupts and subroutine calls.


What is the difference between register stacks and memory stacks?

Registers are normally memory spaces internal to the processor or very close to it. They are generally faster than main memory and will be small in size and will hold very frequently used data.Register stacks are a set of such register memory locations.Memory refers to computers main memory outside CPU. It is used to keep data and programs. Memory stack is a series of memory locations.The difference between register stack and memory stack is...


What is Usage of stack register?

The stack register points to the top of the stack for the currently executing thread. The stack is a fixed-length memory allocation at the bottom of addressable memory (highest available address). The stack extends upwards into lower addresses. To keep track of the stack's usage, the stack pointer marks the top of the stack where a new frame will be pushed, decrementing the stack pointer by the required amount. When a frame is popped, the stack pointer is incremented by the frame length. The stack is typically used to call and return from functions by storing the return address of the caller, but can also be used to store a function's arguments (the values passed to it by its caller), its local variables and its exception handlers. Since the memory is allocated as soon as the thread becomes active, moving a pointer to activate and release stack frames is much quicker than requesting heap memory via the operating system.


What is heaped?

The heap is a section of memory controlled by a program used for dynamic variable allocation. Heap size is the size of that section of memory.


What is the meaning of a stack overflow?

A stack overflow is a programming term used to identify when a function tries to access memory from a stack that does not exist. A stack, such as a queue or array, contains a limited number of memory spaces set aside when it is created. For example, if an array has 8 objects in it and a function tried to access an item at slot nine, which doesn't exist, it would cause a stack overflow.


Can ROM be used as stack?

No. ROM means read-only memory so, by definition, you can't write to it.


What is the CPU stack?

CPUcentral processing unitStack1. An orderly pile, especially one arranged in layers.2. A section of memory and its associated registers used for temporary storage of information in which the item most recently stored is the first to be retrieved.D.Ghosh Roy


What is difference between heap memory and stack memory?

Difference between Stack vs Heap memory"Stack memory" and "Heap memory" are physically the same. The same chip of RAM may be used as stack memory when running one program and later used as heap memory when running some other program.The difference is in how they are used.StackOften a function or method calls another function which in turn calls another function etc.The execution of all those functions remains suspended until the very last function returns its value.All the information required to resume the execution of these functions is stored on the stack.In particular, local variables are stored on the stack.Local variables are often stored for short amounts of time while a function/method block uses them to compute a task.Once a function/method has completed its cycle, the space on the stack used by all local variables is freed.This chain of suspended function calls is the stack, because elements in the stack (function calls) depend on each other.The stack is important to consider in exception handling and thread executions.HeapHeapThe heap is simply the memory used by programs to store global variables.Element of the heap (variables) have no dependencies with each other and can always be accessed randomly at any time.All global variables are stored in heap memory.All variables dynamically created by the program with "new()" or "malloc()" or similar commands are also stored on the heap.In some programming languages, all instances of an object, including all the attributes of that instance, are stored on the heap.In those programming languages, local variables of a function that have object type are implemented as creating the new object on the heap,and storing a reference to that object in the local variable, which is on the stack.When that function exits, the heap memory used by each local variable that has object is freed, and then all the stack used by that stack is freed.ComparisonA Heap reference is also stored in Stack memory until the life cycle of the object has completed. Inside the Heap reference all the the contents of the object are stored whereas with a local variable only the variable contents are stored in the stack.Example:Stackvar bluevar redref 0x456783 (Heap reference)var tomref 0x498702 (Heap reference)var dianeHeap (0x456783)name => Susanage => 26city => Londonheight => 5'7sex => femaleHeap (0x498702)name => Paulage => 21city => Glasgowheight => 6'0sex => maleIn addition to heap memory and stack memory, a completely separate section of memory stores the constructors and other methods of a class/object.


What is the difference between stack and heap memory in C?

stack is memory allocated for temporary variables used by subroutinesheap is memory allocated for long term data structures (e.g. linked lists, trees) that are likely to change sizeBoth are forms of dynamically allocated memory (i.e. allocated/deallocated at runtime as needed), but the allocation/deallocation method and their place in physical/virtual memory are differentStatically allocated memory (i.e. allocated at compile/link time) is used for variables and data structures that must exist as long as the program is running and cannot change in size while the program is running.


Where linked list using?

linked list are used for creation of stack,queues to use memory in optimum manner linked list are used as they are dynamic in nature


Why is this following C program returning a Segmentation Fault 11?

Without seeing the code it is impossible to say, however the error indicates the code has caused a stack overflow and that typically indicates a recursive function that either has no end-point or has an end-point that exceeds the limits of the call stack. Either that or you have attempted to allocate memory upon the stack when there is insufficient unused memory available on the stack. The call stack is a fixed length memory allocation used to store thread-local variables, return addresses and formal arguments. Every thread of execution has its own call stack, but once a stack is exhausted or there is insufficient space to meet an allocation at runtime, the thread cannot proceed and thus terminates with a segmentation fault.


What is meaning of stack?

A large pile of hay, grain, straw, or the like, usually of a nearly conical form, but sometimes rectangular or oblong, contracted at the top to a point or ridge, and sometimes covered with thatch., A pile of poles or wood, indefinite in quantity., A pile of wood containing 108 cubic feet., A number of flues embodied in one structure, rising above the roof. Hence:, Any single insulated and prominent structure, or upright pipe, which affords a conduit for smoke; as, the brick smokestack of a factory; the smokestack of a steam vessel., A section of memory in a computer used for temporary storage of data, in which the last datum stored is the first retrieved., A data structure within random-access memory used to simulate a hardware stack; as, a push-down stack., To lay in a conical or other pile; to make into a large pile; as, to stack hay, cornstalks, or grain; to stack or place wood.