Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The Rust Programming Language
Search
Hyeon Kim
May 09, 2015
Programming
8
1.9k
The Rust Programming Language
2015 spring, UPnL workshop.
Hyeon Kim
May 09, 2015
Tweet
Share
More Decks by Hyeon Kim
See All by Hyeon Kim
Adopting Rust to a club
simnalamburt
3
980
Other Decks in Programming
See All in Programming
CursorはMCPを使った方が良いぞ
taigakono
1
170
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
260
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
150
Go1.25からのGOMAXPROCS
kuro_kurorrr
1
800
地方に住むエンジニアの残酷な現実とキャリア論
ichimichi
5
1.3k
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
170
DroidKnights 2025 - 다양한 스크롤 뷰에서의 영상 재생
gaeun5744
3
310
なぜ「共通化」を考え、失敗を繰り返すのか
rinchoku
1
480
Elixir で IoT 開発、 Nerves なら簡単にできる!?
pojiro
1
150
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
340
GraphRAGの仕組みまるわかり
tosuri13
7
480
Webの外へ飛び出せ NativePHPが切り拓くPHPの未来
takuyakatsusa
2
340
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
94
14k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Adopting Sorbet at Scale
ufuk
77
9.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Measuring & Analyzing Core Web Vitals
bluesmoon
7
490
Code Review Best Practice
trishagee
68
18k
Statistics for Hackers
jakevdp
799
220k
Six Lessons from altMBA
skipperchong
28
3.8k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Done Done
chrislema
184
16k
Transcript
The Rust Programming Language 쉽고 안전한 시스템 프로그래밍 김지현 2015-05-09
발표자 소개 13학번 김지현 UPnL 서버관리자 (2014~now) @simnalamburt
target non-target 시스템 프로그래밍을 하고싶으신분, 하게되실분 시스템 프로그래밍 안할 사람
이 발표는 새내기들을 위해 난이도조절 되어있습니다.
Why Rust <****> 러스트를 시작하고 인기남이 되었어요!
빠르다 안전하다 쉽다 Fast Safe Easy
빠르다 안전하다 쉽다 Fast Safe Easy
Dennis MacAlistair Ritchie 1941 ~ 2011 UNIX, C
malloc(), free() • 원하는 양의 메모리를 할당, 프로그래머에게 준다 •
프로그래머에겐 정리의 의무가 있음 void *malloc(size_t size); void free(void *ptr)
malloc(), free() • 받아왔던 주소값을 free()에 넘기면 끗 • 근데
까먹고 안하면 Leakage void *mem = malloc(100); /* ... */ free(mem);
malloc(), free() • 중간에 함수 조기종결이라도 한다면? • 꼼꼼해져야함 void
*mem = malloc(100); /* ... */ if (some_problem) { free(mem); return; } /* ... */ free(mem);
malloc(), free() • 할당을 셋 이상 하면? • 조기종결을 세번
이상 하면?
malloc(), free() • 할당을 셋 이상 하면? • 조기종결을 세번
이상 하면?
void *mem1 = malloc(100); void *mem2 = malloc(1000); /* ...
*/ if (some_problem) { free(mem1); free(mem2); return; } /* ... */ void *mem3 = malloc(10000); if (another_problem) { free(mem1); free(mem2); free(mem3); return; } /* ... */ if (yet_another_problem) { free(mem1); free(mem2); free(mem3); return; } /* ... */ free(mem1); free(mem2); free(mem3);
void *mem1 = malloc(100); void *mem2 = malloc(1000); /* ...
*/ if (some_problem) { free(mem1); free(mem2); return; } /* ... */ void *mem3 = malloc(10000); if (another_problem) { free(mem1); free(mem2); free(mem3); return; } /* ... */ if (yet_another_problem) { free(mem1); free(mem2); free(mem3); return; } /* ... */ free(mem1); free(mem2); free(mem3);
void *mem1 = malloc(100); void *mem2 = malloc(1000); /* ...
*/ if (some_problem) { free(mem1); free(mem2); return; } /* ... */ void *mem3 = malloc(10000); if (another_problem) { free(mem1); free(mem2); free(mem3); return; } /* ... */ if (yet_another_problem) { free(mem1); free(mem2); free(mem3); return; } /* ... */ free(mem1); free(mem2); free(mem3);
void *mem1 = malloc(100); void *mem2 = malloc(1000); /* ...
*/ if (some_problem) { free(mem1); free(mem2); return; } /* ... */ void *mem3 = malloc(10000); if (another_problem) { free(mem1); free(mem2); free(mem3); return; } /* ... */ if (yet_another_problem) { free(mem1); free(mem2); free(mem3); return; } /* ... */ free(mem1); free(mem2); free(mem3);
사실 이렇게 하면 됨 • 문제 해결? void *mem1 =
malloc(100); void *mem2 = 0; void *mem3 = 0; /* ... */ if (some_problem) { goto ERROR; } mem2 = malloc(1000); /* ... */ mem3 = malloc(10000); if (another_problem) { goto ERROR; } /* ... */ if (yet_another_problem) { goto ERROR; } /* ... */ ERROR: free(mem1); mem1 = 0; free(mem2); mem2 = 0; free(mem3); mem3 = 0;
사실 이렇게 하면 됨 • 문제 해결? • malloc(), free()
외에 다른 리소 스 할당을 스택 쌓듯이 하면? • double-free, use-after-free 에 서 안전한가? • 여전히 free 까먹고 안할 가능성 void *mem1 = malloc(100); void *mem2 = 0; void *mem3 = 0; /* ... */ if (some_problem) { goto ERROR; } mem2 = malloc(1000); /* ... */ mem3 = malloc(10000); if (another_problem) { goto ERROR; } /* ... */ if (yet_another_problem) { goto ERROR; } /* ... */ ERROR: free(mem1); mem1 = 0; free(mem2); mem2 = 0; free(mem3); mem3 = 0;
사실 이렇게 하면 됨 • 문제 해결? • malloc(), free()
외에 다른 리소 스 할당을 스택 쌓듯이 하면? • double-free, use-after-free 에 서 안전한가? • 여전히 free 까먹고 안할 가능성 void *mem1 = malloc(100); void *mem2 = 0; void *mem3 = 0; /* ... */ if (some_problem) { goto ERROR; } mem2 = malloc(1000); /* ... */ mem3 = malloc(10000); if (another_problem) { goto ERROR; } /* ... */ if (yet_another_problem) { goto ERROR; } /* ... */ ERROR: free(mem1); mem1 = 0; free(mem2); mem2 = 0; free(mem3); mem3 = 0;
사실 이렇게 하면 됨 • 문제 해결? • malloc(), free()
외에 다른 리소 스 할당을 스택 쌓듯이 하면? • double-free, use-after-free 에 서 안전한가? • 여전히 free 까먹고 안할 가능성 void *mem1 = malloc(100); void *mem2 = 0; void *mem3 = 0; /* ... */ if (some_problem) { goto ERROR; } mem2 = malloc(1000); /* ... */ mem3 = malloc(10000); if (another_problem) { goto ERROR; } /* ... */ if (yet_another_problem) { goto ERROR; } /* ... */ ERROR: free(mem1); mem1 = 0; free(mem2); mem2 = 0; free(mem3); mem3 = 0;
C++ Golden Rule Resource Acquisition Is Initialization
C++, RAII • 소멸자 문법 • 괄호가 열리면, 닫힐것이 무조건
보장됨 struct raii { raii() { hello(); } ~raii() { bye(); } }; int main() { for (int a = 0; a < 10; ++a) { raii a; // 자동으로 hello() 가 호출됨 /* ... */ } // 스코프를 빠져나가면 자동으로 bye() 가 호출됨 }
스마트 포인터 • 똑똑한 포인터 { int *dumb = new
int(10); /* ... */ } // <- LEAK! { auto smart = unique_ptr(new int(10)); /* ... */ } // <- RAII ♥
이제 진짜 된건가?!
None
1. 배우기 어렵다 2. 실수하기 쉽다 C++의 문제
1. 배우기 어렵다 2. 실수하기 쉽다 C++의 문제
1. 배우기 어렵다 2. 실수하기 쉽다 C++의 문제
C++ is not even close to memory safety • Dangling
reference auto list = vector<int>(); /* ... */ auto& elem = list[0]; list.push_back(100); cout << elem; // BOOM!!
Case study: Firefox • 파이퍼폭스 버그, 보안취약점들의 원인중 double free,
user after free가 여전히 상위권임
Case study: Mabinogi 2
Case study: Mabinogi 2
Admit it C++ is not that good
Admit it C++ is not that good 여전히 좋다고 생각하신다면
스톡홀름 증후군을 의심해보십시오
“원래 기존의것을 낫게 만드는게 새 언어 만들어서 하는것보다 훨씬 힘들어.”
멀티코어 컴퓨팅 연구실 이재진 교수님 5월 6일 301동 101호 멀티코어 수업 시간중 발췌
“원래 기존의것을 낫게 만드는게 새 언어 만들어서 하는것보다 훨씬 힘들어.”
멀티코어 컴퓨팅 연구실 이재진 교수님 5월 6일 301동 101호 멀티코어 수업 시간중 발췌 “기존의것을 낫게 만드느니 새 언어 만드는게 훨씬 쉬워.”
None
None
“To design and implement a safe, concurrent, practical, static systems
language.”
fn main() { println!("Hello, world!"); } http://rust-lang.org
Why Rust <****> 러스트를 시작하고 인기남이 되었어요!
빠르다 안전하다 쉽다 Fast Safe Easy
빠르다 안전하다 쉽다 Fast Safe Easy
LLVM
LLVM • 컴파일러 기반구조 • 훌륭하신 분들이 잘 만들어놨음
LLVM • 컴파일러 기반구조 • 훌륭하신 분들이 잘 만들어놨음
빠르다 안전하다 쉽다 Fast Safe Easy
None
None
None
None
None
빠르다 안전하다 쉽다 Fast Safe Easy
쉬웡 C++ • 암걸리는 문법 • 배울게 걍 많음 •
Makefile, autoconf, cmake, ninja, ... • 통일된 패키지매니저 X Rust • 젊음 • 간단함 • cargo • cargo https://crates.io • 매크로, annotation, ...
디펜던시 관리 • 걍 pip, npm, gem 얘네랑 다를거 없음
• 이러면 원터치로 다 설치됨 • 반면 C++에선 컴파일옵션 바꾸고 경로설정하고 라이 브러리마다 설치방법 다 다르고 난리를 치지 [dependencies] time = "*" glutin = "*"
rustdoc 기본 내장 • 코드에 주석만 적절히 달면
rustdoc 기본 내장
rustdoc 기본 내장
디버깅 • gdb, lldb, 자기가 원하는거 쓰면 됨 • LLVM
기반이다보니 Xcode로도 디버그할 수 있음
“Rust Once, Run Everywhere” 크로스 플랫폼
빠르다 안전하다 쉽다 Fast Safe Easy
빠르다 안전하다 쉽다 Fast Safe Easy 5월 15일 Rust 1.0.0
이 출시될 예정
좋은 커뮤니티 • 레딧, IRC, 자체 포럼 • #rust, #rust-gamedev,
#rust-webdev, #servo, ...
rust-kr.org • 한달에 한번씩 모여서 코딩모임을 함 • 학교 밖에
계시는 좋은 분들을 많이 만날수 있는 안 흔한 기회!
제안: UPnL 여름 Rust 스터디 • 먼저 Rust에 대해 배우고,
각자, 혹은 같이 뭔가를 만들면서 진행하고자 함 • 기대효과 • 시프에 익숙해지면 C/C++ 익히는데에도 훨씬 도움 많이 될거에염 • 덜 잉여한 여름방학 • 새내기의 경우 선배들을 뜯어먹을 수 있음 • 필참자 • sgkim • apple • kinetic
내가 한것 • obj-rs Wavefront OBJ 3D 모델 파서
근황 • Rust + OpenGL로 3D 대전액션게임 만드는중 • 빠름
+ 크로스플랫폼 • sgkim이랑 같이하는중 • 관심있는 새내기는 연락하시오
Any Question? 김지현