<commit_before>﻿using System;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace SharpVk
{
    /// <summary>
    /// 
    /// </summary>
    public static class MemUtil
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static uint SizeOf<T>()
        {
            return SizeOfCache<T>.SizeOf;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        private static class SizeOfCache<T>
        {
            public static readonly uint SizeOf;

            static SizeOfCache()
            {
                SizeOf = (uint)Marshal.SizeOf(typeof(T));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dest"></param>
        /// <param name="value"></param>
        /// <param name="startIndex"></param>
        /// <param name="count"></param>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public unsafe static void WriteToPtr<T>(IntPtr dest, T[] value, int startIndex, int count)
            where T : struct
        {
            if (count > 0)
            {
                int elementSize = (int)SizeOf<T>();
                int transferSize = elementSize * count;

                byte* pointer = (byte*)dest.ToPointer();

                var handle = GCHandle.Alloc(value, GCHandleType.Pinned);

                byte* handlePointer = (byte*)handle.AddrOfPinnedObject().ToPointer();

                //HACK Replace with by-platform optimisations
                for (int index = 0; index < transferSize; index++)
                {<commit_msg>Update MemUtil.cs<commit_after>﻿using System;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace SharpVk
{
    /// <summary>
    /// 
    /// </summary>
    public static class MemUtil
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static uint SizeOf<T>()
        {
            return SizeOfCache<T>.SizeOf;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        private static class SizeOfCache<T>
        {
            public static readonly uint SizeOf;

            static SizeOfCache()
            {
                SizeOf = (uint)Marshal.SizeOf(typeof(T));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dest"></param>
        /// <param name="value"></param>
        /// <param name="startIndex"></param>
        /// <param name="count"></param>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public unsafe static void WriteToPtr<T>(IntPtr dest, T[] value, int startIndex, int count)
            where T : struct
        {
            if (count > 0)
            {
                int elementSize = (int)SizeOf<T>();
                int transferSize = elementSize * count;
                int startOffset = elementSize * startIndex;

                byte* pointer = (byte*)dest.ToPointer();
                pointer += startOffset;

                var handle = GCHandle.Alloc(value, GCHandleType.Pinned);

                byte* handlePointer = (byte*)handle.AddrOfPinnedObject().ToPointer();

                //HACK Replace with by-platform optimisations
                for (int index = 0; index < transferSize; index++)
                {
{'fraction_non_alphanumeric': 0.13936627282491945, 'fraction_numerical': 0.0010741138560687433, 'mean_word_length': 1.530570652173913, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1521447', 'n_tokens_mistral': 1020, 'n_tokens_neox': 963, 'n_words': 215}