Click to See Complete Forum and Search --> : some questions


Amaterasu85
October 13th, 2009, 08:00 AM
Hello, i like the c++ syntax, and have been using it for a long time, but some things are **** easy to write in C# (like data bases with MSSQL).
1. Do you think mixing languages slows the program? (i think yes)
2. Have tried to declare "pure c++ vars" in a ref class but there was an error... and i can't declare ref class variables as global or in "a pure class"?
3. Would you recommend getting deeper into managed c++/cli?

Thanks in advance :)

Alex F
October 13th, 2009, 08:34 AM
1. Yes, because every managed-unmanaged transition is relatively expensive.

2. Managed class can be moved my Garbage Collector. Therefore, GC must know how to move every ref class member. Since GC doesn't have idea how to move unmanaged class instance, C++/CLI compiler doesn't allow this. However, you can keep unmanaged class pointer as ref class member. Create unmanaged class instance in a ref class constructor, and release it in destructor/finalizer.
To keep ref class as a native class member, use gcroot keyword.

3. No. Make everything possible in C# or native C++. C++/CLI is the only lenguage allowing to write mixed managed/unmanaged code, and used only for interoperability. If you have .NET application and native library, C++/CLI can be used to write native library wrapper for pure .NET client. Interoperability is the only reason one can decide to use C++/CLI.