Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
333
6
표준 러스트를 넘어서
여기서 이번 아이템 전체의 주제를 볼 수 있다. 즉,
FFI
를 사용하면 표준 러스트에는 없던 위
험에 노출된다는 것이다. 이런 위험과 대가를 잘 알고 있다면 위험을 감수하고
FFI
를 사용해도
좋다.
FFI
경계 너머로 전달되는 대상을 세밀하게 제어한다면 그런 위험을 어느 정도는 줄일
수 있지만, 완전히 제거할 수는 없다.
러스트를 호출하는
C
코드에 대한
FFI
경계를 제어할 때 주의할 점이 하나 더 있다. 러스트 코
드에서 아이템
18
의 조언을 따르지 않는다면,
panic
!
FFI
경계를 넘어가지 않게 해야 한다.
렇게 하지 않으면 예상치 못한 나쁜 동작이 발생한다(
https
://
oreil
.
ly
/
qmUe0
).
14
기억할 사항
다른 언어로 작성한 코드와 연동할 때는
C
를 최소 공배수처럼 여긴다. 따라서 모든 심벌이 단일 글로벌
네임스페이스에 존재한다.
FFI
경계에서 문제가 발생할 가능성을 최소화하려면 다음과 같이 한다.
-
unsafe
FFI
코드를 안전한 래퍼에 캡슐화한다.
- 메모리 할당과 해제를
FFI
경계의 어느 한쪽에서만 수행한다.
- 데이터 구조가
C
호환 레이아웃을 갖게 만든다.
- 크기가 지정된 정수 타입을 사용한다.
- 표준 라이브러리의
FFI
관련 헬퍼를 사용한다.
-
panic!
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

이펙티브 타입스크립트

이펙티브 타입스크립트

Dan Vanderkam
파이썬으로 살펴보는 아키텍처 패턴

파이썬으로 살펴보는 아키텍처 패턴

오현석, 해리 퍼시벌, 밥 그레고리

Publisher Resources

ISBN: 9791169212946