static int __CreateInstance(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (LuaAPI.lua_gettop(L) == 1)
                {
                    Microsoft.IO.RecyclableMemoryStreamManager gen_ret = new Microsoft.IO.RecyclableMemoryStreamManager();
                    translator.Push(L, gen_ret);

                    return(1);
                }
                if (LuaAPI.lua_gettop(L) == 4 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4))
                {
                    int _blockSize           = LuaAPI.xlua_tointeger(L, 2);
                    int _largeBufferMultiple = LuaAPI.xlua_tointeger(L, 3);
                    int _maximumBufferSize   = LuaAPI.xlua_tointeger(L, 4);

                    Microsoft.IO.RecyclableMemoryStreamManager gen_ret = new Microsoft.IO.RecyclableMemoryStreamManager(_blockSize, _largeBufferMultiple, _maximumBufferSize);
                    translator.Push(L, gen_ret);

                    return(1);
                }
            }
            catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(LuaAPI.luaL_error(L, "invalid arguments to Microsoft.IO.RecyclableMemoryStreamManager constructor!"));
        }
 public void OneTimeSetUp()
 {
     // for validating benchmark tests
     m_context       = new ServiceMessageContext();
     m_memoryManager = new Microsoft.IO.RecyclableMemoryStreamManager();
     m_memoryStream  = new MemoryStream();
 }
        static int _e_UsageReport(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                int gen_param_count         = LuaAPI.lua_gettop(L);
                Microsoft.IO.RecyclableMemoryStreamManager gen_to_be_invoked = (Microsoft.IO.RecyclableMemoryStreamManager)translator.FastGetCSObj(L, 1);
                Microsoft.IO.RecyclableMemoryStreamManager.UsageReportEventHandler gen_delegate = translator.GetDelegate <Microsoft.IO.RecyclableMemoryStreamManager.UsageReportEventHandler>(L, 3);
                if (gen_delegate == null)
                {
                    return(LuaAPI.luaL_error(L, "#3 need Microsoft.IO.RecyclableMemoryStreamManager.UsageReportEventHandler!"));
                }

                if (gen_param_count == 3)
                {
                    if (LuaAPI.xlua_is_eq_str(L, 2, "+"))
                    {
                        gen_to_be_invoked.UsageReport += gen_delegate;
                        return(0);
                    }


                    if (LuaAPI.xlua_is_eq_str(L, 2, "-"))
                    {
                        gen_to_be_invoked.UsageReport -= gen_delegate;
                        return(0);
                    }
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            LuaAPI.luaL_error(L, "invalid arguments to Microsoft.IO.RecyclableMemoryStreamManager.UsageReport!");
            return(0);
        }
示例#4
0
        static StackObject *GetStream_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 5);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Int32 @count = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Int32 @offset = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.Byte[] @buffer = (System.Byte[]) typeof(System.Byte[]).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 4);
            System.String @tag = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 5);
            Microsoft.IO.RecyclableMemoryStreamManager instance_of_this_method = (Microsoft.IO.RecyclableMemoryStreamManager) typeof(Microsoft.IO.RecyclableMemoryStreamManager).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.GetStream(@tag, @buffer, @offset, @count);

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
示例#5
0
        static StackObject *Ctor_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *__ret = ILIntepreter.Minus(__esp, 0);

            var result_of_this_method = new Microsoft.IO.RecyclableMemoryStreamManager();

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
        static int _s_set_AggressiveBufferReturn(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                Microsoft.IO.RecyclableMemoryStreamManager gen_to_be_invoked = (Microsoft.IO.RecyclableMemoryStreamManager)translator.FastGetCSObj(L, 1);
                gen_to_be_invoked.AggressiveBufferReturn = LuaAPI.lua_toboolean(L, 2);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(0);
        }
        static int _s_set_MaximumStreamCapacity(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                Microsoft.IO.RecyclableMemoryStreamManager gen_to_be_invoked = (Microsoft.IO.RecyclableMemoryStreamManager)translator.FastGetCSObj(L, 1);
                gen_to_be_invoked.MaximumStreamCapacity = LuaAPI.lua_toint64(L, 2);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(0);
        }
        static int _g_get_GenerateCallStacks(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                Microsoft.IO.RecyclableMemoryStreamManager gen_to_be_invoked = (Microsoft.IO.RecyclableMemoryStreamManager)translator.FastGetCSObj(L, 1);
                LuaAPI.lua_pushboolean(L, gen_to_be_invoked.GenerateCallStacks);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(1);
        }
        static int _g_get_MaximumBufferSize(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                Microsoft.IO.RecyclableMemoryStreamManager gen_to_be_invoked = (Microsoft.IO.RecyclableMemoryStreamManager)translator.FastGetCSObj(L, 1);
                LuaAPI.xlua_pushinteger(L, gen_to_be_invoked.MaximumBufferSize);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(1);
        }
示例#10
0
        public void CouldUseSafeWriteReadArray()
        {
            var doChecks = false;

            var count = doChecks ? 100 : 100_000;
            var size  = 1000;


            var rng    = new Random();
            var bytes  = new byte[size];
            var bytes2 = new byte[size];

            var msManager = new Microsoft.IO.RecyclableMemoryStreamManager();

            rng.NextBytes(bytes);
            for (int r = 0; r < 20; r++)
            {
                using (Benchmark.Run("Spreads.RMS", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var stream = RecyclableMemoryStreamManager.Default.GetStream();
                        stream.SafeWrite(bytes, 0, bytes.Length);
                        var targetPos = 0L;
                        stream.SafeRead(bytes2, 0, bytes2.Length, ref targetPos);
                        if (doChecks && targetPos != bytes.Length)
                        {
                            ThrowHelper.ThrowInvalidOperationException();
                        }
                        if (doChecks)
                        {
                            Assert.True(bytes.SequenceEqual(bytes2));
                        }
                        stream.Dispose();
                    }
                }

                using (Benchmark.Run("Original", count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var stream = msManager.GetStream() as Microsoft.IO.RecyclableMemoryStream;
                        stream.Write(bytes, 0, bytes.Length);
                        stream.Dispose();
                    }
                }
            }

            Benchmark.Dump($"Write/Read buffer with size = {size}");
        }
示例#11
0
        static int __CreateInstance(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (LuaAPI.lua_gettop(L) == 2 && translator.Assignable <Microsoft.IO.RecyclableMemoryStreamManager>(L, 2))
                {
                    Microsoft.IO.RecyclableMemoryStreamManager _memoryManager = (Microsoft.IO.RecyclableMemoryStreamManager)translator.GetObject(L, 2, typeof(Microsoft.IO.RecyclableMemoryStreamManager));

                    Microsoft.IO.RecyclableMemoryStream gen_ret = new Microsoft.IO.RecyclableMemoryStream(_memoryManager);
                    translator.Push(L, gen_ret);

                    return(1);
                }
                if (LuaAPI.lua_gettop(L) == 3 && translator.Assignable <Microsoft.IO.RecyclableMemoryStreamManager>(L, 2) && (LuaAPI.lua_isnil(L, 3) || LuaAPI.lua_type(L, 3) == LuaTypes.LUA_TSTRING))
                {
                    Microsoft.IO.RecyclableMemoryStreamManager _memoryManager = (Microsoft.IO.RecyclableMemoryStreamManager)translator.GetObject(L, 2, typeof(Microsoft.IO.RecyclableMemoryStreamManager));
                    string _tag = LuaAPI.lua_tostring(L, 3);

                    Microsoft.IO.RecyclableMemoryStream gen_ret = new Microsoft.IO.RecyclableMemoryStream(_memoryManager, _tag);
                    translator.Push(L, gen_ret);

                    return(1);
                }
                if (LuaAPI.lua_gettop(L) == 4 && translator.Assignable <Microsoft.IO.RecyclableMemoryStreamManager>(L, 2) && (LuaAPI.lua_isnil(L, 3) || LuaAPI.lua_type(L, 3) == LuaTypes.LUA_TSTRING) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4))
                {
                    Microsoft.IO.RecyclableMemoryStreamManager _memoryManager = (Microsoft.IO.RecyclableMemoryStreamManager)translator.GetObject(L, 2, typeof(Microsoft.IO.RecyclableMemoryStreamManager));
                    string _tag           = LuaAPI.lua_tostring(L, 3);
                    int    _requestedSize = LuaAPI.xlua_tointeger(L, 4);

                    Microsoft.IO.RecyclableMemoryStream gen_ret = new Microsoft.IO.RecyclableMemoryStream(_memoryManager, _tag, _requestedSize);
                    translator.Push(L, gen_ret);

                    return(1);
                }
            }
            catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(LuaAPI.luaL_error(L, "invalid arguments to Microsoft.IO.RecyclableMemoryStream constructor!"));
        }
示例#12
0
 public static void SetRecyclableMemoryStreamManager(Microsoft.IO.RecyclableMemoryStreamManager recyclableMemoryStreamManager)
 {
     _memoryManager = recyclableMemoryStreamManager;
 }
示例#13
0
 public static void SetRecyclableMemoryStreamManager(Microsoft.IO.RecyclableMemoryStreamManager recyclableMemoryStreamManager)
 {
     _dataInitialized = recyclableMemoryStreamManager is object;
     _memoryManager   = recyclableMemoryStreamManager;
 }
示例#14
0
 public RecyclableMemoryStream(Microsoft.IO.RecyclableMemoryStreamManager manager, string tag, int requestedSize)
 {
     this.innerMemStream = new Microsoft.IO.RecyclableMemoryStream(manager, tag, requestedSize);
 }
示例#15
0
 public RecyclableMemoryStream(Microsoft.IO.RecyclableMemoryStreamManager manager, string tag)
 {
     this.innerMemStream = new Microsoft.IO.RecyclableMemoryStream(manager, tag);
 }
示例#16
0
        public void CouldUseSafeWriteReadByte()
        {
            var doChecks = true;
            var count    = doChecks ? 1 : 1000;
            var size     = 1000;

            var rng   = new Random();
            var bytes = new byte[size];

            var msManager = new Microsoft.IO.RecyclableMemoryStreamManager();

            rng.NextBytes(bytes);
            for (int r = 0; r < 20; r++)
            {
                using (Benchmark.Run("RMS", count * 1000))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var stream = RecyclableMemoryStreamManager.Default.GetStream();

                        for (int j = 0; j < bytes.Length; j++)
                        {
                            stream.SafeWriteByte(bytes[j]);
                        }
                        var p = 0L;
                        int b = 0;
                        while ((b = stream.SafeReadByte(ref p)) >= 0)
                        {
                            if (doChecks && bytes[p - 1] != b)
                            {
                                ThrowHelper.ThrowInvalidOperationException();
                            }
                            p++;
                        }
                        stream.Dispose();
                    }
                }

                using (Benchmark.Run("Original", count * 1000))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var stream = msManager.GetStream() as Microsoft.IO.RecyclableMemoryStream;

                        for (int j = 0; j < bytes.Length; j++)
                        {
                            stream.WriteByte(bytes[j]);
                        }
                        var p = 0;
                        int b = 0;
                        while ((b = stream.SafeReadByte(ref p)) >= 0)
                        {
                            if (bytes[p - 1] != b)
                            {
                                ThrowHelper.ThrowInvalidOperationException();
                            }
                            p++;
                        }
                        stream.Dispose();
                    }
                }
            }

            Benchmark.Dump($"Write/Read single byte, buffer size = {size}, MOPS scaled x1k (read as KOPS)");
        }
示例#17
0
 /// <summary>
 /// Creates new instance of Disposable Streams Collection <br/>
 /// Refer to <seealso cref="RecyclableMemoryStreamManager"/> and docs <a href="https://github.com/Microsoft/Microsoft.IO.RecyclableMemoryStream">here</a> for more info on Recycable Memory Streams
 /// </summary>
 /// <param name="blockSize">Size of each block of memory to be pooled by recycling streams manager (must be > 0)</param>
 /// <param name="largeBlockSizeMultiple">Large buffers in recycling streams manager will be multiple of the provided value</param>
 /// <param name="maximumBufferSize">Maximum size of pooled buffers that will be pooled by recycling streams manager (anything above are not pooled)</param>
 /// <param name="useExponentialLargeBuffer">Whether to use exponential large buffer in recycling streams manager</param>
 public DisposableMemoryStreamsCollection(int blockSize, int largeBlockSizeMultiple, int maximumBufferSize, bool useExponentialLargeBuffer)
 {
     _streamManager = new Microsoft.IO.RecyclableMemoryStreamManager(blockSize, largeBlockSizeMultiple, maximumBufferSize, useExponentialLargeBuffer);
     _streams       = new ConcurrentDictionary <Guid, MemoryStream>();
 }
示例#18
0
 /// <summary>
 /// Creates new instance of Disposable Streams Collection
 /// </summary>
 public DisposableMemoryStreamsCollection()
 {
     _streamManager = new Microsoft.IO.RecyclableMemoryStreamManager();
     _streams       = new ConcurrentDictionary <Guid, MemoryStream>();
 }
 public void GlobalSetup()
 {
     m_context       = new ServiceMessageContext();
     m_memoryManager = new Microsoft.IO.RecyclableMemoryStreamManager();
     m_memoryStream  = new MemoryStream();
 }
        static int _m_GetStream(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                Microsoft.IO.RecyclableMemoryStreamManager gen_to_be_invoked = (Microsoft.IO.RecyclableMemoryStreamManager)translator.FastGetCSObj(L, 1);


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 1)
                {
                    System.IO.MemoryStream gen_ret = gen_to_be_invoked.GetStream(  );
                    translator.Push(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING))
                {
                    string _tag = LuaAPI.lua_tostring(L, 2);

                    System.IO.MemoryStream gen_ret = gen_to_be_invoked.GetStream(_tag);
                    translator.Push(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 3 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3))
                {
                    string _tag          = LuaAPI.lua_tostring(L, 2);
                    int    _requiredSize = LuaAPI.xlua_tointeger(L, 3);

                    System.IO.MemoryStream gen_ret = gen_to_be_invoked.GetStream(_tag, _requiredSize);
                    translator.Push(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 4 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3) && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 4))
                {
                    string _tag                = LuaAPI.lua_tostring(L, 2);
                    int    _requiredSize       = LuaAPI.xlua_tointeger(L, 3);
                    bool   _asContiguousBuffer = LuaAPI.lua_toboolean(L, 4);

                    System.IO.MemoryStream gen_ret = gen_to_be_invoked.GetStream(_tag, _requiredSize, _asContiguousBuffer);
                    translator.Push(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 5 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && (LuaAPI.lua_isnil(L, 3) || LuaAPI.lua_type(L, 3) == LuaTypes.LUA_TSTRING) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5))
                {
                    string _tag    = LuaAPI.lua_tostring(L, 2);
                    byte[] _buffer = LuaAPI.lua_tobytes(L, 3);
                    int    _offset = LuaAPI.xlua_tointeger(L, 4);
                    int    _count  = LuaAPI.xlua_tointeger(L, 5);

                    System.IO.MemoryStream gen_ret = gen_to_be_invoked.GetStream(_tag, _buffer, _offset, _count);
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to Microsoft.IO.RecyclableMemoryStreamManager.GetStream!"));
        }