swig를 이용한 c++ 랩핑
TRANSCRIPT
![Page 1: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/1.jpg)
swig 를이용한성능개선용C++ 모듈랩핑
![Page 2: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/2.jpg)
Is python slow?
![Page 3: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/3.jpg)
C/C++ == Speed
출처: https://attractivechaos.github.io/plb/
![Page 4: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/4.jpg)
Java Native Interface, JNI
![Page 5: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/5.jpg)
먼저랩퍼클래스를만든다
![Page 6: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/6.jpg)
그걸컴파일하면헤더파일이나온다
![Page 7: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/7.jpg)
헤더파일의시그네처를복붙한다
![Page 8: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/8.jpg)
python API#include <Python.h>
![Page 9: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/9.jpg)
그냥쓰면된다
![Page 10: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/10.jpg)
하지만데이터를 Python API 로직접파싱및생성해야한다
![Page 11: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/11.jpg)
Platform InvokeP/Invoke
![Page 12: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/12.jpg)
DLL 을만든다음 Pinvoke로랩핑한다
![Page 13: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/13.jpg)
각언어를위해특별히코드를작성해야하기도한다.
랩핑을해줘야하는경우도있다
타입간에마샬링을직접해줘야하는경우도있다
![Page 14: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/14.jpg)
![Page 15: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/15.jpg)
![Page 16: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/16.jpg)
Interface File C/C++ Source File C/C++ Header File
SWIG C/C++ Compiler
C++ WrapperSource File
Target LanguageWrapper Source File
Shared Library
![Page 17: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/17.jpg)
Header.h
![Page 18: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/18.jpg)
Test.i
![Page 19: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/19.jpg)
C:\Users\User> swig –csharp Test.i
![Page 20: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/20.jpg)
Why Should I Use This????
![Page 21: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/21.jpg)
TestClass.cs
![Page 22: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/22.jpg)
ConsoleAppPInvoke.cs
![Page 23: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/23.jpg)
예외처리가매우확실하다
100프로터진다
![Page 24: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/24.jpg)
개발사이클이엄청짧아진다
![Page 25: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/25.jpg)
하지만물론단점도있다
툴이지원하는 C/C++ 기능들에함정이엄청많다
툴이지원하는 C/C++ 기능들이한정적이다
레퍼런스겁나길다… 진짜로..
언어별로툴이처리하는방식이다르다
![Page 26: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/26.jpg)
사용하기위해서는 Swig 가지원하는범위와, 처리하는방법을잘파악해야한다
std::auto_ptrstd::dequestd::liststd::mapstd::setstd::stringstd::vectorstd::arraystd::shared_ptr
![Page 27: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/27.jpg)
출처: http://www.techmikael.com/2010/01/net-serialization-performance.html
![Page 28: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/28.jpg)
swig.org
![Page 29: swig를 이용한 C++ 랩핑](https://reader030.vdocuments.pub/reader030/viewer/2022012402/58a2cdad1a28ab692e8b462b/html5/thumbnails/29.jpg)