Rust lang
StackOverflow - Most loved
Rust timeline
StackOverflow - Most popular
C++ malloc / free
Python - Reference counting
Reference couting
Go GC improvements
Java GC
Rust in 100 seconds
Rust doc - Ownership
Last active
September 13, 2022 19:16
-
-
Save oscarryz/f29b6a0f9bf5d9574e7ac5b4b4941896 to your computer and use it in GitHub Desktop.
Rust Memory Management Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char** argv) | |
{ | |
char* h = "hello"; // char* -> ['h' 'e' 'l' 'l' 'o' '\0'] length: 5 | |
char* w = "world"; | |
// printf("%s, %s!\n", h, w); | |
// char* s = "secret"; | |
// printf("%s, %s %s!\n", h, &h[12], w); | |
// printf("%s, %s %s!\n", h, h+12, w); | |
// | |
// int i; | |
// for (i = 0 ; i < 19; i++ ) { | |
// printf(" %c ", h[i]); | |
// } | |
// printf("\n"); | |
// for (i = 0 ; i < 19; i++ ) { | |
// printf("0x%x ", h[i]); | |
// } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main() { | |
string h = "Hello"; | |
string w = "world"; | |
string s = "secret"; | |
cout << h.length() << endl; | |
cout << h << "," << w << "!" << endl; | |
cout << "[" << h[19] << "]"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let h = String::from("Hello"); | |
let w = String::from("world"); | |
println!("{h}, {w}!"); | |
// let s = String::from("secret"); | |
// println!("s: {s}"); | |
// let t = s; | |
// println!("s: {s}"); | |
// println!("t: {t}"); | |
// let v = thing(t); | |
// println!("t: {t}"); | |
// println!("{v}"); | |
// let x = size(&v); | |
// println!("{v}"); | |
// println!("{x}"); | |
} | |
// fn thing(s: String) -> String { | |
// let r = s.chars().rev().collect::<String>(); | |
// r | |
// } | |
// fn size(s: &String) -> usize { | |
// let size = s.len(); | |
// size | |
// } | |
// fn dangle() -> &String { | |
// let stuff = &String::from("new stuff"); | |
// return stuff; | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment