当前位置: 首页>>代码示例>>C#>>正文


C# IntPtr.ToPointer方法代码示例

本文整理汇总了C#中IntPtr.ToPointer方法的典型用法代码示例。如果您正苦于以下问题:C# IntPtr.ToPointer方法的具体用法?C# IntPtr.ToPointer怎么用?C# IntPtr.ToPointer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IntPtr的用法示例。


在下文中一共展示了IntPtr.ToPointer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UmsManager

 public unsafe UmsManager(FileAccess access, byte[] seedData)
 {
     int memorySizeInBytes = seedData.Length;
     _memory = Marshal.AllocHGlobal(memorySizeInBytes);
     byte* destination = (byte*)_memory.ToPointer();
     fixed (byte* source = seedData)
     {
         Buffer.MemoryCopy(source, destination, memorySizeInBytes, memorySizeInBytes);
     }
     _stream = new UnmanagedMemoryStream(destination, memorySizeInBytes, memorySizeInBytes, access);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:11,代码来源:UmsManager.cs

示例2: CopyUnmanagedMemory

        public static void CopyUnmanagedMemory(IntPtr src, int srcOffset, IntPtr dst, int dstOffset, int count)
        {
            unsafe
            {
                var srcPtr = (byte*) src.ToPointer();
                srcPtr += srcOffset;
                var dstPtr = (byte*) dst.ToPointer();
                dstPtr += dstOffset;

                memcpy(dstPtr, srcPtr, count);
            }
        }
开发者ID:ahamling27-xx,项目名称:Terraria-Map-Editor,代码行数:12,代码来源:NativeMethods.cs

示例3: UmsManager

 public unsafe UmsManager(FileAccess access, byte[] seedData)
 {
     _memorySizeInBytes = seedData.Length;
     unsafe
     {
         _memory = Marshal.AllocHGlobal(_memorySizeInBytes);
         byte* bytes = (byte*)_memory.ToPointer();
         byte* currentByte = bytes;
         for (int index = 0; index < _memorySizeInBytes; index++)
         {
             *currentByte = seedData[index];
         }
         _stream = new UnmanagedMemoryStream(bytes, _memorySizeInBytes, _memorySizeInBytes, access);
     }
 }
开发者ID:gitter-badger,项目名称:corefx,代码行数:15,代码来源:UmsManager.cs

示例4: PosTest1

    unsafe public bool PosTest1(string id, long anyValue)
    {
        bool retVal = true;
        try
        {
            System.IntPtr ip = new IntPtr((void *)anyValue);
            if (ip.ToPointer() != (void*)anyValue)
            {
                TestLibrary.TestFramework.LogError(id, String.Format("expect IntPtr value is {0}", anyValue));
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError(id, "Unexpected exception: " + e);
            retVal = false;
        }


        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:21,代码来源:intptrctor_void.cs

示例5: RaiseFailFastException

        //
        // Wrapper for calling RaiseFailFastException
        //
        internal static unsafe void RaiseFailFastException(uint faultCode, IntPtr pExContext)
        {
            long ctxIP = 0;
            Interop._CONTEXT* pContext = (Interop._CONTEXT*)pExContext.ToPointer();
            if (pExContext != IntPtr.Zero)
            {
#if AMD64
                ctxIP = (long)pContext->Rip;
#elif ARM
                ctxIP = (long)pContext->Pc;
#elif X86
                ctxIP = (long)pContext->Eip;
#else
                System.Diagnostics.Debug.Assert(false, "Unsupported architecture");
#endif
            }

            _EXCEPTION_RECORD exceptionRecord;
            exceptionRecord.ExceptionCode = faultCode;
            exceptionRecord.ExceptionFlags = (uint)Constants.ExceptionNonContinuable;
            exceptionRecord.ExceptionRecord = IntPtr.Zero;
            exceptionRecord.ExceptionAddress = new IntPtr(ctxIP);  // use the IP set in context record as the exception address
            exceptionRecord.NumberParameters = 0;
            // don't care about exceptionRecord.ExceptionInformation as we set exceptionRecord.NumberParameters to zero

            PInvoke_RaiseFailFastException(
                &exceptionRecord,
                pContext,
                ctxIP == 0 ? (uint)Constants.FailFastGenerateExceptionAddress : 0);
        }
开发者ID:jango2015,项目名称:corert,代码行数:33,代码来源:Interop.manual.cs

示例6: Add

    /// <summary>
    /// erstellt einen neuen Hash-Eintrag (darf noch nicht vorhanden sein)
    /// </summary>
    /// <param name="code">Hash-Code, welcher eintragen werden soll</param>
    /// <param name="tiefe">entsprechende Zugtiefe</param>
    public void Add(ulong code, int tiefe)
    {
#if multiHash
      var hash = hashes[code & hashesBits];
#endif
      hash.Add(code, (ushort)tiefe);

      if (hash.Count > dictionaryLimit)
      {
#if Index0
        Array.Resize(ref weitere, weitere.Length + 1);
        for (int i = weitere.Length - 1; i > 0; i--) weitere[i] = weitere[i - 1];
        weitere[0] = hash;
        hash = new Dictionary<ulong, ushort>();
#endif

#if Index16
        if (archivAnzahl == 0)
        {
          #region # // --- Archiv das erste mal erstellen ---
          // --- Archiv vorbereiten ---
#if multiHash
          archivAnzahl = hashes.Sum(x => x.Count);
#else
          archivAnzahl = hash.Count;
#endif

          archivDataPointer = Marshal.AllocHGlobal((IntPtr)((long)archivAnzahl * 8L));
          if (archivDataPointer == IntPtr.Zero) throw new Exception("Speicher konnte nicht reserviert werden (" + (((long)archivAnzahl * 8L) / 1048576L) + " MB)");
          archivData = (ulong*)archivDataPointer.ToPointer();

          uint[] zähler = new uint[1 << 16];
#if multiHash
          foreach (var h in hashes)
          {
            h.Select(x => zähler[x.Key & 0xffff]++).Count();
          }
#else
          hash.Select(x => zähler[x.Key & 0xffff]++).Count();
#endif
          uint[] posis = new uint[1 << 16];
          uint pos = 0;
          for (int i = 1; i < (1 << 16); i++)
          {
            pos += zähler[i - 1];
            posis[i] = pos;
          }

          // --- Archiv befüllen ---
#if multiHash
          foreach (var h in hashes) foreach (var satz in h)
#else
          foreach (var satz in hash)
#endif
            {
              int indexPos = (int)(satz.Key & 0xffff);
              archivData[posis[indexPos]++] = (satz.Key & 0xffffffffffff0000) | (ulong)satz.Value;
            }

          // --- Positionen neu berechnen ---
          posis[0] = pos = 0;
          for (int i = 1; i < (1 << 16); i++)
          {
            pos += zähler[i - 1];
            posis[i] = pos;
          }

          // --- Archiv sortieren (Multi-Threaded) ---
          ParallelEnumerable.Range(0, 1 << 16).Select(i =>
          {
            Sort.Quick(&archivData[posis[i]], (int)zähler[i]);
            return i;
          }).Count();

          // --- 16 Bit-Index erstellen ---
          uint[] indexTemp = Enumerable.Range(0, (1 << 16) * 2).Select(i => (i & 1) == 0 ? zähler[i >> 1] : posis[i >> 1]).ToArray();

          for (int i = 0; i < indexTemp.Length; i++) archivIndex[i] = indexTemp[i];
          #endregion
        }
        else
        {
          #region # // --- Archiv erweitern ---
          // --- Neue Daten vorbereiten ---
          int dazuAnzahl = hash.Count;
          ulong[] dazuData = new ulong[dazuAnzahl];
          uint[] zähler = new uint[1 << 16];
          hash.Select(x => zähler[x.Key & 0xffff]++).Count();
          uint[] posis = new uint[1 << 16];
          uint pos = 0;
          for (int i = 1; i < (1 << 16); i++)
          {
            pos += zähler[i - 1];
            posis[i] = pos;
          }
//.........这里部分代码省略.........
开发者ID:MaxKlaxxMiner,项目名称:SokoWahn,代码行数:101,代码来源:SokowahnHash_Index0.cs

示例7: Libgit2Object

 internal unsafe Libgit2Object(IntPtr ptr, bool owned)
     : this(ptr.ToPointer(), owned)
 {
 }
开发者ID:PKRoma,项目名称:libgit2sharp,代码行数:4,代码来源:Libgit2Object.cs

示例8: SetUnmanagedMemory

 /// <summary>
 /// Fill memory region with specified value.
 /// </summary>
 /// 
 /// <param name="dst">Destination pointer.</param>
 /// <param name="filler">Filler byte's value.</param>
 /// <param name="count">Memory block's length to fill.</param>
 /// 
 /// <returns>Return's value of <paramref name="dst"/> - pointer to destination.</returns>
 /// 
 public static IntPtr SetUnmanagedMemory(IntPtr dst, int filler, int count)
 {
     unsafe
     {
         SetUnmanagedMemory((byte*)dst.ToPointer(), filler, count);
     }
     return dst;
 }
开发者ID:salmangadit,项目名称:project-pinnacle,代码行数:18,代码来源:PreProcessor.cs

示例9: SokowahnHash_Index24

    public SokowahnHash_Index24()
#endif
#endif
    {
#if multiHash
      hashes = new Dictionary<ulong, ushort>[hashesAnzahl];
      for (int i = 0; i < hashes.Length; i++) hashes[i] = new Dictionary<ulong, ushort>();
#else
      hash = new Dictionary<ulong, ushort>();
#endif

#if Index16
      archivIndexPointer = Marshal.AllocHGlobal((1 << 16) * 2 * 4);
      if (archivIndexPointer == IntPtr.Zero) throw new Exception("Speicher konnte nicht reserviert werden (" + (((1 << 16) * 2 * 4) / 1048576L) + " MB)");
      archivIndex = (uint*)archivIndexPointer.ToPointer();
      for (int i = 0; i < (1 << 16) * 2; i++) archivIndex[i] = 0;
#endif

#if Index24
      archivIndexPointer = Marshal.AllocHGlobal((1 << 24) * 2 * 4);
      if (archivIndexPointer == IntPtr.Zero) throw new Exception("Speicher konnte nicht reserviert werden (" + (((1 << 24) * 2 * 4) / 1048576L) + " MB)");
      archivIndex = (uint*)archivIndexPointer.ToPointer();
      for (int i = 0; i < (1 << 24) * 2; i++) archivIndex[i] = 0;
#endif
    }
开发者ID:MaxKlaxxMiner,项目名称:SokoWahn,代码行数:25,代码来源:SokowahnHash_Index0.cs

示例10: OnCallback

 unsafe static void OnCallback(IntPtr handle, int status)
 {
     uv_req_t* uvRequest = (uv_req_t*)handle.ToPointer();
     var request = GCHandle.FromIntPtr(uvRequest->data).Target as CallbackRequest;
     if (request == null)
     {
         throw new Exception("invalid callback");
     }
     else
     {
         request.Callback(status);
         request.Dispose();
     }
 }
开发者ID:jkotas,项目名称:corefxlab,代码行数:14,代码来源:Request.cs

示例11: CopyUnmanagedMemory

 /// <summary>
 /// Copy block of unmanaged memory.
 /// </summary>
 /// 
 /// <param name="dst">Destination pointer.</param>
 /// <param name="src">Source pointer.</param>
 /// <param name="count">Memory block's length to copy.</param>
 /// 
 /// <returns>Return's value of <paramref name="dst"/> - pointer to destination.</returns>
 /// 
 /// <remarks><para>This function is required because of the fact that .NET does
 /// not provide any way to copy unmanaged blocks, but provides only methods to
 /// copy from unmanaged memory to managed memory and vise versa.</para></remarks>
 ///
 public static IntPtr CopyUnmanagedMemory(IntPtr dst, IntPtr src, int count)
 {
     unsafe
     {
         CopyUnmanagedMemory((byte*)dst.ToPointer(), (byte*)src.ToPointer(), count);
     }
     return dst;
 }
开发者ID:salmangadit,项目名称:project-pinnacle,代码行数:22,代码来源:PreProcessor.cs

示例12: runTest

 public unsafe virtual bool runTest()
   {
   Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   IntPtr ip1;
   void* vd1;
   void* vd2;
   int* iptr1;
   Int32 iValue;          
   Int64 lValue;
   Boolean fValue;
   Char chValue;
   Byte btValue;
   SByte sbValue;
   Int16 sValue;
   UInt16 usValue;
   UInt32 uiValue;
   UInt64 ulValue;
   DateTime dt1;
   String strValue;
   Int32[] iArr = {1, 2, 3, 4, 5};
   MyEnum en1;
   String strReturned;
   try {
   strLoc = "Loc_743wg";
   iValue = 16;
   vd1 = &iValue;
   ip1 = new IntPtr(vd1);
   vd2 = ip1.ToPointer();
   iCountTestcases++;
   if((*((int*)vd2)) != iValue){
   iCountErrors++;
   Console.WriteLine("Err_2975sf! Wrong value returned, " + (*((int*)vd2)));
   }
   strLoc = "Loc_0084wf";
   lValue = 16;
   vd1 = &lValue;
   ip1 = new IntPtr(vd1);
   vd2 = ip1.ToPointer();
   iCountTestcases++;
   if((*((long*)vd2)) != lValue){
   iCountErrors++;
   Console.WriteLine("Err_974325sdg! Wrong value returned");
   }
   strLoc = "Loc_0084wf";
   lValue = 16;
   vd1 = &lValue;
   ip1 = new IntPtr(vd1);
   iptr1 = (int*)ip1.ToPointer();
   iCountTestcases++;
   if((*iptr1) != lValue){
   iCountErrors++;
   Console.WriteLine("Err_974325sdg! Wrong value returned! check the endiannees of this machine!!!, " + (*iptr1));
   }
   strLoc = "Loc_00845wsdg";
   lValue = Int64.MaxValue;
   vd1 = &lValue;
   ip1 = new IntPtr(vd1);
   vd2 = ip1.ToPointer();
   iCountTestcases++;
   if((*((long*)vd2)) != lValue){
   iCountErrors++;
   Console.WriteLine("Err_94753sdg! Wrong value returned");
   }
   strLoc = "Loc_875esfg";
   lValue = Int64.MaxValue;
   vd1 = &lValue;
   ip1 = new IntPtr(vd1);
   iptr1 = (int*)ip1.ToPointer();
   iCountTestcases++;
   if((*iptr1) != -1){
   iCountErrors++;
   Console.WriteLine("Err_756wrg! Wrong value returned! , " + (*iptr1));
   }
   strLoc = "Loc_008742sf";
   fValue = true;
   vd1 = &fValue;
   ip1 = new IntPtr(vd1);
   iCountTestcases++;
   if((*((Boolean*)ip1.ToPointer())) != fValue){
   iCountErrors++;
   Console.WriteLine("Err_984753sdg! Wrong value returned!");
   }
   strLoc = "Loc_735sdg";
   chValue = 'a';
   vd1 = &chValue;
   ip1 = new IntPtr(vd1);
   iptr1 = (int*)ip1.ToPointer();
   iCountTestcases++;
   if((*((char*)ip1.ToPointer())) != chValue){
   iCountErrors++;
   Console.WriteLine("Err_9745sg! Wrong value returned!");
   }
   strLoc = "Loc_735sdg";
   btValue = 5;
   vd1 = &btValue;
   ip1 = new IntPtr(vd1);
   iCountTestcases++;
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8531topointer.cs

示例13: FromUtf8

		internal static string FromUtf8(IntPtr ptr)
		{
			int length = 0;
			unsafe
			{
				byte* p = (byte*) ptr.ToPointer();
				while (*p++ != 0)
					length++;
			}

			return FromUtf8(ptr, length);
		}
开发者ID:sakurahoshi,项目名称:System.Data.SQLite,代码行数:12,代码来源:SQLiteConnection.cs

示例14: OnCallback

 unsafe static void OnCallback(IntPtr handle, int status)
 {
     uv_req_t* uvRequest = (uv_req_t*)handle.ToPointer();
     var request = GCHandle.FromIntPtr(uvRequest->data).Target as DisposeRequest;
     if (request == null)
     {
         Environment.FailFast("invalid callback");
     }
     else
     {
         request._handle.Dispose();
         request.Dispose();
     }
 }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:14,代码来源:Request.cs

示例15: ConvertToNative

        [System.Security.SecurityCritical]  // auto-generated
        static internal unsafe IntPtr ConvertToNative(string strManaged, IntPtr pNativeBuffer) 
        {
            if (null == strManaged) 
            { 
                return IntPtr.Zero;
            } 
            else
            {
                StubHelpers.CheckStringLength(strManaged.Length);
 
                byte trailByte;
                bool hasTrailByte = strManaged.TryGetTrailByte(out trailByte); 
 
                uint lengthInBytes = (uint)strManaged.Length * 2;
 
                if (hasTrailByte)
                {
                    // this is an odd-sized string with a trailing byte stored in its [....] block
                    lengthInBytes++; 
                }
 
                byte *ptrToFirstChar; 

                if (pNativeBuffer != IntPtr.Zero) 
                {
                    // If caller provided a buffer, construct the BSTR manually. The size
                    // of the buffer must be at least (lengthInBytes + 6) bytes.
#if _DEBUG 
                    uint length = *((uint *)pNativeBuffer.ToPointer());
                    BCLDebug.Assert(length >= lengthInBytes + 6, "BSTR localloc'ed buffer is too small"); 
#endif // _DEBUG 

                    // set length 
                    *((uint *)pNativeBuffer.ToPointer()) = lengthInBytes;

                    ptrToFirstChar = (byte *)pNativeBuffer.ToPointer() + 4;
                } 
                else
                { 
                    // If not provided, allocate the buffer using SysAllocStringByteLen so 
                    // that odd-sized strings will be handled as well.
                    ptrToFirstChar = (byte *)Win32Native.SysAllocStringByteLen(null, lengthInBytes).ToPointer(); 
                }

                // copy characters from the managed string
                fixed (char* ch = strManaged) 
                {
                    Buffer.memcpyimpl( 
                        (byte *)ch, 
                        ptrToFirstChar,
                        (strManaged.Length + 1) * 2); 
                }

                // copy the trail byte if present
                if (hasTrailByte) 
                {
                    ptrToFirstChar[lengthInBytes - 1] = trailByte; 
                } 

                // return ptr to first character 
                return (IntPtr)ptrToFirstChar;
            }
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:64,代码来源:StubHelpers.cs


注:本文中的IntPtr.ToPointer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。