28
votes
How are variables stored in and retrieved from the program stack?
Storing local variables on a stack is an implementation detail – basically an optimization. You can think of it this way. When entering a function, space for all local variables is allocated somewhere....
26
votes
How are variables stored in and retrieved from the program stack?
Having y on the stack doesn't physically prevent x from being accessed, which, as you pointed out, makes computer stacks ...
16
votes
What course in CS deals with the study of RAM, CPU, Storage?
The subject you're describing often goes under the names computer architecture, computer systems, computer organization and design, and the like. One example is Elements of computing systems, based on ...
15
votes
How are variables stored in and retrieved from the program stack?
To provide a concrete example of how a compiler manages the stack and how values on the stack are accessed, we can look at visual depictions, plus code generated by ...
9
votes
How are variables stored in and retrieved from the program stack?
There are two special registers: ESP (stack pointer) and EBP (base pointer).
When a procedure is invoked the first two operations are usually
...
9
votes
How are variables stored in and retrieved from the program stack?
You are confused because the local variables stored in stack are not accessed with the access rule of stack: First In Last Out, or just FILO.
The thing is that the FILO rule applies to function call ...
6
votes
What is the time complexity of memory allocation assumed to be?
what would the worst-case complexity be if it didn't have to copy over $n$ items? If it only needed to allocate a buffer with size $O(n)$ when resizing, would that be considered to run $O(1)$ or $O(n)$...
5
votes
Accepted
Do modern operating systems use memory control blocks?
This is really a question about memory allocators and doesn't have much to do with operating systems. "Memory control block" does seem to be a DOS specific term for a node in a free list. I'm not ...
5
votes
How is heap memory allocated to a process?
Short answer, summarizing the other answers: It is done by the operating system. Simple (early) operating systems assigned fixed size areas for code, data, stack + heap (with the idea that the stack ...
5
votes
Accepted
How is the formula for calculation in row/column major obtained?
Row-major order stores the rows of the array one after another in memory. That is, the array
a d g j
b e h k
c f i l
is stored as
...
5
votes
Random access memory and data
RAM is cleared after each power cycle.
The power-up value of cells depends on the technology.
Static RAM content is usually random (there is no preference between 0 and 1, but the same chip may ...
4
votes
Why is data fragmentation not possible on main memory (RAM)?
According to https://lwn.net/Articles/211505/, what you imagine should be done by the OS, is already done:
Since Linux is a virtual memory system, fragmentation normally is not a problem; ...
4
votes
Accepted
Row Major Vs Column Major Order: 2D arrays access in programming languages
The way you access the array affects performance.
It depends on how the matrix is represented and stored in memory. Often a matrix is stored in row-major order, so that consecutive elements of a row ...

D.W.♦
- 156k
4
votes
How are variables stored in and retrieved from the program stack?
There are many ways to implement local variables by a language runtime system. Using a stack is a common efficient solution, used in many practical cases.
Intuitively, a stack pointer ...
4
votes
Accepted
Is it theoretically possible to dynamically grow array size in stack memory?
Yes, it is certainly possible. It really depends if you want it enough to pay the price in terms of complication.
First of all, I would strongly recommend that your array should have negative indices:...
4
votes
Accepted
Buddy system allocator and slab allocator in Linux kernel
A modern operating system manages physical memory as page frames. A page frame can be allocated to a user process or for the kernel to use for its own purposes, such as to allocate its own data ...
3
votes
Memory address of variable after reassignment
"Local variable" is a concept in the source language. Some target languages have the concept (e.g. virtual machines with dictionary-based scopes), but many do not. Since you're using Java, let's look ...
3
votes
How are variables stored in and retrieved from the program stack?
The easiest idea is to think of variables as fix names for addresses in memory. Indeed, some assemblers display machine code that way ("store value 5 in address i", ...
3
votes
Accepted
How does malloc(sizeof(char)) work
Quick note, sizeof(char) is defined to be 1. So you can just simplify to malloc(1).
The real answer however is quite boring. ...
3
votes
Accepted
Does word addressable memory have more bytes than byte addressable memory?
If you had a byte addressable architecture where pointers have a fixed size, and every or almost every bit pattern is a valid pointer to a distinct byte address, and a word addressable architecture ...
3
votes
Understanding memory leaks in C/C++
In your second example, you allocate space for a PrimeSet object and initialise it, then you call the countPrimeNumbers function. The PrimeSet object still exists, it still occupies memory, it ...
3
votes
Why does a 32 bit address only contain 1 byte, when 32 bits = 4 bytes?
The question is confusingly worded, but if the question is "why a pointer of 32 bits (4 bytes) points to only one byte of storage", that is just how a particular computer architecture (like ...
3
votes
How does a CPU jump to a instruction thats no longer in ram?
The program counter holds an address. Period. The CPU fetches an instruction from that address. Period.
Most CPUs today have a hardware unit called an MMU (memory management unit) which sits between ...
2
votes
How is heap memory allocated to a process?
To answer your question 1, the short answer is yes. The long answer is when an executable is linked, there are also fields in the executable header (For Unix and Unix-Like operating systems, it's ELF....
2
votes
Accepted
Why not space out memory allocations?
Why is memory different from a hard disk?
Because hard disks have different performance characteristics than RAM.
With hard disks, seeking is extremely slow. Sequential reads are much faster than ...

D.W.♦
- 156k
2
votes
Does word addressable memory have more bytes than byte addressable memory?
How is it possible that tha same ram, i.e given the ram size is 4 GB, would contain different number of bytes depending on byte/ word addressable memory?
It isn't. a 4GB amount of ram would either ...
2
votes
Row Major Vs Column Major Order: 2D arrays access in programming languages
It's a completely arbitrary decision. In Fortran, for example, "people" prefer column-major order, whereas in C "they" prefer row-major order.
In C the row-major order is forced due to reasons of ...
2
votes
Accepted
Less used data (1 byte) in memory address holding 4 bytes
So your computer has 32 bits as the smallest addressable unit.
Your compiler has two choices: It can store var1 and var2 in two different sets of 8 bits in the same 32 bit unit, or it can store var1 ...
2
votes
How are variables stored in and retrieved from the program stack?
Data items that can go on the stack are put on the stack - Yes! It is a premium space. Also, Once we pushed x into stack and then pushed ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
memory-allocation × 79memory-management × 28
operating-systems × 19
memory-access × 18
virtual-memory × 15
memory-hardware × 14
computer-architecture × 13
algorithms × 5
data-structures × 5
cpu × 5
paging × 5
arrays × 4
stacks × 4
c × 3
storage × 3
time-complexity × 2
programming-languages × 2
compilers × 2
c++ × 2
garbage-collection × 2
complexity-theory × 1
turing-machines × 1
algorithm-analysis × 1
optimization × 1
terminology × 1