IL2CPP OPTIMIZATION : Avoid Boxing
__Boxing__은 코스트가 높은 연산이다. 이 글에서는 기존 C# 컴파일러는 특정한 상황에서 불필요한 Boxing이 수행되고, IL2CPP가 이를 어떻게 회피하는지를 보여준다.
https://github.com/pjc0247/to.cpp/blob/master/to.h
C++에는 기본적으로 타입
이라는 타입이 없고, __RTTI__의 기능은 굉장히 제한적입니다. 하지만 컴파일 타임에는 해당 타입의 여러가지 정보를 가져오거나, 두개의 타입이 같은지 비교하는것도 가능합니다.
이미 __std__네임스페이스 아래에는 수많은 타입 유틸리티들이 포함되어 있으며, to.cpp
프로젝트에서는 아래와같은 함수들을 사용하였습니다. (이름이 직관적이기 때문에 별도의 설명은 달지 않도록 하겠습니다.)
- std::is_same
- std::is_pointer
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
public void AddExceptionHandler() | |
{ | |
// 유니티 메인 스레드가 아닌 다른 스레드에서 발생한 익셉션은 여기로 핸들링됩니다. | |
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; | |
#pragma warning disable 0618 | |
// 유니티 스레드에서 발생된 익셉션은 여기로 핸들링됩니다. | |
UnityEngine.Application.RegisterLogCallback((condition, stackTrace, type) => | |
{ | |
if (type != LogType.Exception) |
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
// totest.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다. | |
#include <string> | |
constexpr unsigned short _make_16(unsigned char a, unsigned char b) { | |
return ((unsigned short)((a & 0xff) | ((b & 0xff) << 8))); | |
} | |
constexpr unsigned char _lo_8(unsigned short a) { | |
return ((unsigned char)(a & 0xff)); | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Reflection; | |
using System.Reflection.Emit; | |
namespace Oven |