34 lines
613 B
Markdown
34 lines
613 B
Markdown
# memory-models
|
|
|
|
Memory models in C for researching static compiler analysis
|
|
|
|
Many people overhype the rust borrow checker, i'm going to prove how terrible it is by creating a better memory model.
|
|
|
|
## Current iteration
|
|
|
|
It's called `sc` (scope counting), think of it as a relative counter to the lifetime of a variable.
|
|
|
|
```rust
|
|
{
|
|
let x = Box::new(10); // sc = 0
|
|
|
|
// sc is 0, drop it
|
|
}
|
|
```
|
|
|
|
```rust
|
|
let r; // sc = 0
|
|
|
|
{
|
|
// sc of r = -1 (relative to current scope)
|
|
|
|
let x = Box::new(10); // sc = 0
|
|
|
|
r = &x; // sc of x = -(sc of r) aka 1
|
|
|
|
// sc is 1, don't drop it
|
|
}
|
|
|
|
// sc is 0, drop it
|
|
```
|