alg | data.structure Pointer

 
1. Enable Unsafe in project property.
 
2. 在會用到指標的函式(function)內加上unsafe標籤,舉例如下:
static void newsub() //一般宣告
static unsafe void newsub() //函式內會用到指標,加上unsafe標籤
3. declare pointer in statement "fixed (...)"
        static unsafe void test()
{
int[] iarray = { 1, 2, 3, 4, 5 };
string s = "abcde";

fixed (int* ptr_i1 = iarray, ptr_i2 = &iarray[2])
{
fixed (char* ptr_c=s )
{
Console.WriteLine(*ptr_i1);
Console.WriteLine(*(ptr_i2+1));
Console.WriteLine(*ptr_c);
Console.WriteLine(*(ptr_c+3));
Console.WriteLine(new string(ptr_c));
}
}
}
C++撰寫DLL給C#使用(跨平台)
http://sculptor9.pixnet.net/blog/post/42489892
C++指標物件與實體物件-資料傳遞與資料擷取
http://sculptor9.pixnet.net/blog/post/42489888
陣列指標是否有替代方案 
http://social.msdn.microsoft.com/Forums/zh-HK/233/thread/56625033-8852-41d0-ac13-6cef5b2cb5f9
Return unmanaged object pointer in C#
http://stackoverflow.com/questions/6663489/return-unmanaged-object-pointer-in-c-sharp
 
http://sculptor9.pixnet.net/blog/post/42489890-c%23%E5%82%B3%E6%8C%87%E6%A8%99%E7%B5%A6c%2B%2B
http://piggy0227.wordpress.com/2009/05/25/c%E7%94%A8%E6%8C%87%E6%A8%99%E5%AD%98%E5%8F%96%E5%BD%B1%E5%83%8F%E7%9A%84%E6%96%B9%E6%B3%95/
Subpages (1): alg.pointer | Reference
ċ
unsafe.zip
(9k)
Vincent Yeh,
Mar 11, 2012, 8:07 PM
Comments