RSS 2.0 Feed
2005-11 Entries
摘要: 在VC.Net中使用默认设置/clr编译时,一个托管函数会产生两个入口点,一个是托管的,供托管代码调用,另外一个是非托管的,供非托管代码调用。但是函数地址,特别是虚函数指针只能有一个值,所以需要有一个默认的入口。非托管入口点可能是所有调用的默认入口(在 Visual Studio .NET2003 中,编译器总是会选择非托管入口,但是在Visual Studio 2005中,如果参数或者返回值中包含托管类型,那么编译器会选择托管入口),而另外一个只是使用托管C++中的互操作功能对默认入口的调用。在一个托管函数被另一个托管函数调用的时候,这可能会造成不必要的托管/非托管上下文切换和参数/返回值的复制。如果函数不会被非托管代码使用指针调用,那么可以在声明函数时用VC2005新增的__clrcall修饰符阻止编译器生成两个入口。现在用简单的冒泡排序算法来比较一下使用__clrcall之后的性能改善程度。 using namespace System; #define ARRAY_SIZE 1000 struct bubbleBase ...{ int value; }; class bubble1:public bubbleBase ...{ public: virtual int getvalue()...{return value;} virtual void setvalue(int newvalue)...{value=newvalue;} }; class bubble2:public bubbleBase ...{ public: virtual int __clrcall getvalue()...{return value;} virtual void __clrcall setvalue(int newvalue)...{value=newvalue;} }; template<class T> void bubbleSort(int length) ...{ TimeSpan ts; T* array1=new T[ARRAY_SIZE]; for (int i=0;i<ARRAY_SIZE ;i++) ...{ array1[i].setvalue(ARRAY_SIZE-i-1); } ......[阅读全文]

posted @ | Feedback (1) | Filed Under [ 随笔 .Net Framework 编译(CodeGen) 类库(Library) 语言(Language) C++/CLI/Managed C++ Extension ]

摘要:C#程序员可以用三个斜杠来开始XML格式的注释,而且编译器可以据此生成可用于自动生成帮助文档的XML文件。Visual C++ 2005中的编译器也支持了这个功能,而且对非托管函数也生效,前提是必须打开/clr和/DOC开关,并且不能使用/clr:oldSyntax开关编译。/**//// ///Use two bubble sort steps ///to show the performance information ///of different function calls. /// int main(array<System::String ^> ^args) ...{ bubbleSort<bubble1>(ARRAY_SIZE); bubbleSort<bubble2>(ARRAY_SIZE); return 0; } #pragma unmanaged /**//// ///testing unmanaged function... /// int foo() ...{ return 0; } 有空的话,多去微软的反馈中心提提对产品的建议是很有好处的…… 参考 /doc (Process Documentation Comments) (C/C++)( http://msdn2.microsoft.com/en-us/library/ms173501.aspx ) XML Comments for Managed C++ Applications (http://www.codeproject.com/dotnet/MCXDoc.asp) NDoc Code Documentation Generator for .NET(http://ndoc.sourceforge.net)...[阅读全文]

posted @ | Feedback (3) | Filed Under [ 编译(CodeGen) 集成开发环境(IDE) 语言(Language) C++/CLI/Managed C++ Extension ]