Skip to main content
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 ...
David Richerby's user avatar
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 ...
Pseudonym's user avatar
  • 23.1k
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,351
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,359
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

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
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 ...
Joey Eremondi's user avatar
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
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.'s user avatar
  • 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 (...
André Souza Lemos's user avatar
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

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
  • 23.1k
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
  • 23.1k
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
  • 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 ...
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,132
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, ...
gnasher729's user avatar
  • 31.4k
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 ...
Knogger's user avatar
  • 1,549
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 ...
Derek Elkins left SE's user avatar
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 ...
Daniel Rodríguez's user avatar
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 ...
Gaya Thamel's user avatar
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 ...
gnasher729's user avatar
  • 31.4k

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