Пример #1
0
        /// <summary>
        /// Writes a single element to the memory location, taking into account the alignment.
        /// </summary>
        /// <typeparam name="T">Struct type</typeparam>
        /// <param name="pDest">Pointer to memory location</param>
        /// <param name="data">The value to write</param>
        public static unsafe void WriteAligned <T>(IntPtr pDest, ref T data) where T : struct
        {
            int pad = (int)(pDest.ToInt64() % (long)IntPtr.Size);

            InternalInterop.WriteInline <T>((void *)AddIntPtr(pDest, pad), ref data);
        }
Пример #2
0
 /// <summary>
 /// Writes data from the array to the memory location.
 /// </summary>
 /// <typeparam name="T">Struct type</typeparam>
 /// <param name="pDest">Pointer to memory location</param>
 /// <param name="data">Array containing data to write</param>
 /// <param name="startIndexInArray">Zero-based element index to start reading data from in the element array.</param>
 /// <param name="count">Number of elements to copy</param>
 public static unsafe void Write <T>(IntPtr pDest, T[] data, int startIndexInArray, int count) where T : struct
 {
     InternalInterop.WriteArray <T>(pDest, data, startIndexInArray, count);
 }
Пример #3
0
 /// <summary>
 /// Writes a single element to the memory location.
 /// </summary>
 /// <typeparam name="T">Struct type</typeparam>
 /// <param name="pDest">Pointer to memory location</param>
 /// <param name="data">The value to write</param>
 public static unsafe void Write <T>(IntPtr pDest, ref T data) where T : struct
 {
     InternalInterop.WriteInline <T>((void *)pDest, ref data);
 }
Пример #4
0
 /// <summary>
 /// Reads a single element from the memory location.
 /// </summary>
 /// <typeparam name="T">Struct type</typeparam>
 /// <param name="pSrc">Pointer to memory location</param>
 /// <returns>The read value</returns>
 public static unsafe T Read <T>(IntPtr pSrc) where T : struct
 {
     return(InternalInterop.ReadInline <T>((void *)pSrc));
 }
Пример #5
0
        /// <summary>
        /// Reads a single element from the memory location, taking into account the alignment.
        /// </summary>
        /// <typeparam name="T">Struct type</typeparam>
        /// <param name="pSrc">Pointer to memory location</param>
        /// <returns>The read value</returns>
        public static unsafe T ReadAligned <T>(IntPtr pSrc) where T : struct
        {
            int pad = (int)(pSrc.ToInt64() % (long)IntPtr.Size);

            return(InternalInterop.ReadInline <T>((void *)AddIntPtr(pSrc, pad)));
        }
Пример #6
0
 /// <summary>
 /// Reads data from the memory location into the array.
 /// </summary>
 /// <typeparam name="T">Struct type</typeparam>
 /// <param name="pSrc">Pointer to memory location</param>
 /// <param name="data">Array to store the copied data</param>
 /// <param name="startIndexInArray">Zero-based element index to start writing data to in the element array.</param>
 /// <param name="count">Number of elements to copy</param>
 public static unsafe void Read <T>(IntPtr pSrc, T[] data, int startIndexInArray, int count) where T : struct
 {
     InternalInterop.ReadArray <T>(pSrc, data, startIndexInArray, count);
 }
Пример #7
0
 /// <summary>
 /// Performs a memcopy that copies data from the memory pointed to by the source pointer to the memory pointer by the destination pointer.
 /// </summary>
 /// <param name="pDest">Destination memory location</param>
 /// <param name="pSrc">Source memory location</param>
 /// <param name="sizeInBytesToCopy">Number of bytes to copy</param>
 public static unsafe void CopyMemory(IntPtr pDest, IntPtr pSrc, int sizeInBytesToCopy)
 {
     InternalInterop.MemCopyInline((void *)pDest, (void *)pSrc, sizeInBytesToCopy);
 }
Пример #8
0
 /// <summary>
 /// Computes the size of the struct array. Only use if the type is blittable, where marshaling by the runtime is NOT required
 /// (e.g. does not have MarshalAs attributes and can have its raw bytes copied), otherwise use the Marshal SizeOf methods for non-blittable types.
 /// </summary>
 /// <typeparam name="T">Struct type</typeparam>
 /// <param name="array">Array of structs</param>
 /// <returns>Total size, in bytes, of the array's contents.</returns>
 public static int SizeOf <T>(T[] array) where T : struct
 {
     return(array == null ? 0 : array.Length *InternalInterop.SizeOfInline <T>());
 }
Пример #9
0
 /// <summary>
 /// Computes the size of the struct type. Only use if the type is blittable, where marshaling by the runtime is NOT required
 /// (e.g. does not have MarshalAs attributes and can have its raw bytes copied), otherwise use the Marshal SizeOf methods for non-blittable types.
 /// </summary>
 /// <typeparam name="T">Struct type</typeparam>
 /// <returns>Size of the struct in bytes.</returns>
 public static unsafe int SizeOf <T>() where T : struct
 {
     return(InternalInterop.SizeOfInline <T>());
 }
Пример #10
0
 /// <summary>
 /// Clears the memory to the specified value.
 /// </summary>
 /// <param name="memoryPtr">Pointer to the memory.</param>
 /// <param name="clearValue">Value the memory will be cleared to.</param>
 /// <param name="sizeInBytesToClear">Number of bytes, starting from the memory pointer, to clear.</param>
 public static unsafe void ClearMemory(IntPtr memoryPtr, byte clearValue, int sizeInBytesToClear)
 {
     InternalInterop.MemSetInline((void *)memoryPtr, clearValue, sizeInBytesToClear);
 }