- USC Framework에 포함될 Xdatabase를 만들기 위해 고민하다 보니, C++/CLI에 대해 관심을 가지게 되었음.
- 성능 개선을 위해 ADO.NET 2.0을 포함하고 싶었으나, ADO.NET 2.0은 .NET Framework에서만 사용이 가능.
- http://en.wikipedia.org/wiki/C%2B%2B/CLI
- 기존의 Managed Extensions for C++를 대체하기 위해 제시한 표준 (ECMA-372)
- 중요한 변화
- Handles
- MC++에는 두 가지 형태의 포인터가 있었음.
- __nogc: Normal C++ pointer type
- __gc: .NET Reference type
- C++/CLI에는 한 가지 형태의 포인터만 존재.
- Normal C++ pointer type
- .NET Reference type은 "핸들"을 통해 접근 가능함.
- 핸들은 ^로 표시 (ClassName^)
- 새로운 문법은, managed 코드와 unmanaged 코드가 공존할 때 유용한데, 이는 어떤 객체가 .NET의 자동 가비지 컬렉션에 의해 해제되고, 어떤 객체가 수동으로 해제되어야 하는지 명확하게 구분해 주기 때문이다.
- 참조 내용
- How handles are different from pointers?
- http://www.codeproject.com/KB/mcpp/cppcliintro01.aspx
- Pointers are denoted using the * punctuator while handles are denoted using the ^ punctuator.
- Handles are managed references to objects on the managed heap, pointers just point to a memory address.
- Pointers are stable and GC cycles do not affect them, handles might keep pointing to different memory locations based on GC and memory compactions.
- For pointers, the programmer must delete explicitly or else suffer a leak. For handles delete is optional.
- Handles are type-safe while pointers are most definitely not. You cannot cast a handle to a void^.
- Just as a new returns a pointer, a gcnew returns a handle.
- MC++에는 두 가지 형태의 포인터가 있었음.
- 코드 형태 비교
- Tracking references
- 함수 호출 시, value 타입이 아니라 reference로 넘기는 변수 타입.
- C++에서 사용하는 *& (Reference to a pointer)와 같은 개념으로, ^%를 사용한다.
(*&(87) vs. ^%(65) 로구만. 짜식들.)
- 이 코드에서 추가적으로 볼 수 있는 것은, C#과 다르게, for each 루틴에서 Reference type을 직접 사용할 수 있다는 점이다. C#에서 이 문법은 허용되지 않는다. (illegal)
- Finalizers and Automatic variables
- !ClassName()
- Garbage collection routine의 일부로 동작
- Object의 Finalize method를 override
- 기존의 Deterministic destructor는 non-managed 객체 또는 시스템 전역 리소스 (네트워크 / 데이터베이스 연결, 파일 스트림 등)의 해제에 사용되고, 그렇지 않은 자원의 경우 non-deterministic destructor가 적절하다.
- Handles
- Benefits
- Elegant syntax and grammar
- First class CLI(Common Language Infrastructure) support
- First class C++ support
- Bridges the gap between .NET and C++
- Executable generated by the C++/CLI is now fully verifiable


Prev
Rss Feed