88
votes
Accepted
Why don't compilers automatically insert deallocations?
Because it's undecidable whether the program will use the memory again. This means that no algorithm can correctly determine when to call free() in all cases, which ...
59
votes
Why don't compilers automatically insert deallocations?
As David Richerby rightly noted, the problem is undecidable in general. Object liveness is a global property of the program, and may in general depend on the inputs to the program.
Even precise ...
30
votes
Why don't compilers automatically insert deallocations?
It's an incompleteness problem, not an undecidability problem
While it's true that the optimal placement of deallocation statements is undecidable, that's simply not the issue here. Since it's ...
27
votes
Accepted
If the virtual address space can be larger than the physical address space, how are the address mappings stored in memory?
The trick to making this work is "paging." When bringing data from a hard disk into physical memory, you don't just bring a few bytes. You bring an entire page. 4k bytes is a very common page size.
...
24
votes
Why don't compilers automatically insert deallocations?
Currently, none of the posted answers are fully correct. It's not impossible to do this, but adding that feature would restrict mermory allocation patterns.
Why don't compilers automatically insert ...
16
votes
automatic memory allocation
There are three types of memory in C: static (global variables), automatic (stack) and dynamic (heap). All three are needed to express programs conveniently and efficiently.
Why static memory is ...
14
votes
Accepted
What does "map" mean?
So, there are two distinct uses of the word "map", that I'll unpack here.
The first is very generic, where map means "to associate," particularly by way of a function. If we say "$f$ maps each $x$ to ...
12
votes
Since programs are swapped from backing store to main memory why don't they get lost when the computer is suddenly turned off?
Because it isn't moved: it's copied.
11
votes
Accepted
How does the TLB identify a particular process?
In the most basic setup, the TLB doesn't determine that. Instead, the TLB only maintains mappings for the pages that are accessible to the current process. If process A is currently running, the TLB ...
D.W.♦
- 164k
10
votes
Why don't compilers automatically insert deallocations?
"Humans do it, so it's not impossible" is a well-known fallacy. We do not necessarily understand (let alone control) the things that we create - money is a common example. We tend to overestimate (...
9
votes
Why don't compilers automatically insert deallocations?
The issue is mostly a historic artifact, not an impossibility of implementation.
The way most C compilers build code is so that the compiler only sees each source file at a time; it never sees the ...
9
votes
Why don't compilers automatically insert deallocations?
The lack of automatic memory management is a feature of the language.
C is not supposed to be a tool for writing software easily. It is a tool for making the computer do whatever you tell it to do. ...
8
votes
What does "map" mean?
In the following I am going to be less than accurate in a number of ways, sacrificing technical accuracy to provide a basic understanding. It is obvious that you have read a number of technical ...
8
votes
Accepted
difference between "addressable" and "address" in memory?
Address is a label that identifies a memory location. The memory is $4$ byte addressable means that you have labels that refer to memory locations of size $4$ bytes. You don't have names for smaller ...
7
votes
Accepted
what is the need for valid/invalid bit in paged memory technique?
In a typical multilevel page table implementation on a typical modern operating system, any attempt to access memory for a page whose page table entry set to "invalid" (typically 0) causes a page ...
7
votes
Why do we need the valid-invalid bit in a page table?
As David Richerby says, it’s not clear what you don't understand.
Most of my answer here has already been presented in answers (or comments)
to the questions you linked to.
I’ll admit, though, that ...
6
votes
What is the difference between a 'page' of memory and a 'frame' of memory?
Physical memory is organized into frames and virtual memory into pages. The "page frame" term is a bit confusing and in my opinion wikipedia shouldn't use it. What they really mean by "page frame" is ...
6
votes
Why don't compilers automatically insert deallocations?
Other answers have focussed on whether it is possible to do garbage collection, some details of how it's done, and some of the problems.
One issue which hasn't yet been covered though is the ...
6
votes
Accepted
Why do modern processors need a runtime stack?
I would say that "required" is a bit of strong word. Processors provide hardware support for stacks to help implement the call stack abstraction. Having special instructions to do so can improve ...
6
votes
Accepted
Where are 'Base & Bounds' registers located?
The values for base and limit must be stored in registers somewhere; it would be highly inefficient to read these from memory on every memory access.
The distinction between "CPU" and "MMU" isn't ...
6
votes
Accepted
Is there any mechanism where the kernel portion of an OS in memory may also be swapped?
Indeed, it wouldn't make sense to swap out an I/O buffer. The point of that buffer is that it's in RAM. The code to perform the I/O and the code to manage swap must not be swapped out either.
Other ...
6
votes
Accepted
Returning random integer from interval based on last result and a seed
I suggest you pick a random permutation on the range $[a,b]$, i.e., a bijective function $\pi:[a,b]\to [a,b]$. Then, maintain a counter $i$ that starts at $i=a$; at each step, output $\pi(i)$ and ...
D.W.♦
- 164k
6
votes
Accepted
Why does page size affect page table size?
Suppose you have a virtual address space of say $32$ bits. Then the virtual address space for each and every process is fixed and it ranges from the byte $0$ to $2^{32}-1$.
Now the for the ease of ...
6
votes
Accepted
What are pointers in low-level language like C
In general, a pointer is a variable which holds the address of a variable. You can use https://godbolt.org/ to find out the assembly equivalent of a pointer. For example,
...
6
votes
In-Place Reordering of Doubly Linked List Nodes to Ensure Memory Contiguity
If you know all pointers to nodes, and you have enough free space for a single node, then you iterate through the nodes. For the I-th node, you copy the node stored at address I to the free space, ...
6
votes
How to allocate memory in NASM without C functions (x64)?
On Linux you can use the brk syscall to extend you data segment.
First call brk(0) to find the break point and then extend your ...
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
Since programs are swapped from backing store to main memory why don't they get lost when the computer is suddenly turned off?
Main memory is volatile, secondary memory is not. The video is physically stored in the secondary memory(hard drive). The main memory just fetches this data and copies it in a location on command by ...
4
votes
Size of address spaces (logical and physical)
Since the page size is 2^10 , in the virtual address, 10 bits are allocated as offset bits. Since it has 32 bits total, the remaining 22 bits represents the Frame number. So there are 2^22 logical ...
4
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
memory-management × 323operating-systems × 123
virtual-memory × 87
computer-architecture × 55
paging × 50
memory-access × 43
memory-hardware × 37
memory-allocation × 31
cpu-cache × 30
algorithms × 13
cpu × 13
garbage-collection × 13
data-structures × 12
programming-languages × 11
compilers × 9
c × 8
reference-request × 7
arrays × 7
stacks × 7
process-scheduling × 6
terminology × 5
threads × 4
os-kernel × 4
storage × 4
cache × 4