86 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 ...
David Richerby's user avatar
58 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 ...
Pseudonym's user avatar
  • 21.7k
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 ...
Nat's user avatar
  • 1,341
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. ...
Cort Ammon's user avatar
  • 3,241
25 votes

Is a computer without RAM, but with a disk, equivalent to one with RAM?

Sure. In principle, given appropriate hardware, you could have just a disk, with everything stored on disk. Any time the CPU did a load or store instruction, there could be some hardware that turns ...
D.W.'s user avatar
  • 156k
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 ...
Paul Draper's user avatar
16 votes

Is a computer without RAM, but with a disk, equivalent to one with RAM?

In terms of computability, it is known that every modern day computer can be simulated by a Turing Machine whose only storage is a single, linear tape cells that can be written. Assuming you can keep ...
jmite's user avatar
  • 29.7k
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 ...
Gilles 'SO- stop being evil''s user avatar
14 votes

Is a computer without RAM, but with a disk, equivalent to one with RAM?

The question is not purely academic. It is a matter of historical record that one of the earliest commercially-produced computers [sorry, I don't recall which offhand] did not have any RAM - all ...
PMar's user avatar
  • 141
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 ...
jmite's user avatar
  • 29.7k
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.
David Richerby's user avatar
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 (...
André Souza Lemos's user avatar
10 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.'s user avatar
  • 156k
9 votes

Is page size always equal to frame size?

A page is a region of virtual address space, and a page frame is a region of physical memory. A page which maps a region of physical memory must have the same size as that piece of physical memory, ...
Pseudonym's user avatar
  • 21.7k
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 ...
Grumbel's user avatar
  • 207
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. ...
Jouni Sirén's user avatar
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 ...
Richard Chambers's user avatar
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 ...
plop's user avatar
  • 1,189
7 votes
Accepted

Why is word-addressable the exception, not the rule?

Byte operations will always be important because a lot of a modern workload involves bytes. Text processing and bytecode interpretation (including emulation of other CPUs) are obvious examples, but ...
Pseudonym's user avatar
  • 21.7k
7 votes

Is a computer without RAM, but with a disk, equivalent to one with RAM?

No. Disk drives are not Random Addressable like RAM. Instead they're block storage devices. You can't read or write a byte from them. And your CPU cannot read a whole sector at once, they need that ...
MSalters's user avatar
  • 865
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 ...
Pseudonym's user avatar
  • 21.7k
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 ...
G-Man Says 'Reinstate Monica''s user avatar
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 ...
KeyC0de's user avatar
  • 162
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 ...
Graham's user avatar
  • 219
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 ...
Amaury Pouly's user avatar
  • 1,181
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 ...
Pseudonym's user avatar
  • 21.7k
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 ...
Gilles 'SO- stop being evil''s user avatar
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.'s user avatar
  • 156k
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 ...
Abhishek Ghosh's user avatar
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, ...
user123's user avatar
  • 1,092

Only top scored, non community-wiki answers of a minimum length are eligible