We need to talk about memory first before talking about GC. So where can variables be stored?
For primitive variables, there are 3 categories (given different lifetimes)
new
to the one that at which they are deallocated with delete
Here is a graph of a process memory:
As we all know, we only do garbage collection on the heap for implicit memory allocation.
Inspired by My Remote Shell Session Setup
My work requires connecting to a few different hosts via ssh. Similar to My Remote Shell Session Setup while still a little different, my personal requirements are as follows:
Some requirements are just copy pasted. Specifically for requirement #1，I used to manage various tabs by using screen/tmux alone. The problem with that approach is when you want to switch to next tab/session, you have to press the escape key (usually ctrl-b or something else) plus another key, which is 3 keys in total. 3 keys are too many for me; I want 2 keys only, so using the tab of the terminal itself might be a good idea. Also, because I need to get access to different hosts, I actually need multiple tmux windows, which is quite inconvenient.
Matrix Game: Two players, each makes a choice secretly and play simutaneously. And there is payoff.
$(X,Y)$ is a saddle point if entry $x$ is the largest value in column $X$ and smallest value in its row.
Thm: All saddle points has the same value and appears as corners of a rectangle.
All examples below are between two players Colin and Ros. Because it is a zero sum game, we only write Rose’s payoff, and Colin’s payoff is just the inverse.
Example:
A | B | |
A | 2 | -3 |
B | -1 | 3 |
If Colin plays $\frac{2}{3}A,\frac{1}{3}B$: Rose A average payout is $2\times\frac{2}{3}-3\times\frac{1}{3}=\frac{1}{3}$ Rose A average payout is $-1\times\frac{2}{3}+3\times\frac{1}{3}=\frac{1}{3}$
For Colin playing $\frac{2}{3}A,\frac{1}{3}B$ minimizes Rose’s maximum average payout; similarly Rose wants to maximize her minimum average payout. So:
So she wants:
So the average payout is $2y-(1-y)=\frac{1}{3}$
Note: If there is a saddle point in the game, then it can’t be solved.
For
a | b |
c | d |
with no dominant row/column:
So for Colin whose payout is $x$:
Normal play: first player who cannot move loses (and therefore no draws)
Two kinds of normal play:
Impartial: For every position the moves available doesn’t depend on whose turn it is. Partisan: Not impartial
Two players are called Louise and Richard. Let $\alpha$ be a position in some normal game:
where $\alpha_i$ is the position where Louise can move from $\alpha$, and $\beta_j$ is the position where $R$ can move from $\alpha$
(L) Louise has a winning strategy regardless of who moves first at $\alpha$ (R) Richard has a winning strategy regardless of who moves first at $\alpha$ (N) Player who moves next has a winning strategy (P) Player who moves previous has a winning strategy
There is a system with $n$ possible states/values. At each step, the state changes probabilistically.
Let $X_t$ be the state of the system at time $t$
So the evolution of the system is: $X_0,X_1,X_2,\cdots,X_t,\cdots$ and $X_0$ is the initial state.
The system is memoryless: the probability that $X_t$ is in a certain state is determined by the state of $X_{t-1}$:
For simplicity, we assume that:
In general, if the initial probabilistic state is $[p_1\ p_2\ \cdots\ p_n]=\pi_0$, where $p_i$ is the probability of being in state $i$, $\sum p_i=1$, and the transition matrix is $T$, such that:
After $t$ more steps, the probabilistic state is:
And the probability of bing in state $i$ after $t$ steps is:
Before we talk about signals, lets go over interrupts and exceptions briefly. The operating system maintains a table of exceptions and interrupts, the entry of each of which corresponds to a handler that gets called when the system gets a specific exception/interrupt. Exceptions and interrupts are inplemented in the hardware and the handlers are maintained by the operating system.
But these two things don’t seem to be enough. What if a process is running and the user hits ctrl-c? How does the process know that it needs to be terminated? So we need some kinds of mechanism for the process to know and act upon some specifi events.
A signal is a small message that notifies a process that an event of some type has occurred in the system.