コード例 #1
0
ファイル: ByteBufTest.cs プロジェクト: jthelin/SparkCLR
 public void CreatePooledBuffer()
 {
     managedBufPool = new ByteBufPool(1024, ByteBufPool.DefaultChunkOrder, false);
     if (SocketFactory.IsRioSockSupported())
     {
         unsafeBufPool = new ByteBufPool(1024, ByteBufPool.DefaultChunkOrder, true);
     }
 }
コード例 #2
0
ファイル: SocketStream.cs プロジェクト: zwffff2015/Mobius
 /// <summary>
 /// Initializes a SocketStream with a RioSocketWrapper object.
 /// </summary>
 /// <param name="socket">a RioSocketWrapper object</param>
 public SocketStream(RioSocketWrapper socket)
 {
     if (socket == null)
     {
         throw new ArgumentNullException("socket");
     }
     streamSocket = socket;
     bufPool      = ByteBufPool.UnsafeDefault;
 }
コード例 #3
0
ファイル: SocketStream.cs プロジェクト: jthelin/SparkCLR
 /// <summary>
 /// Initializes a SocketStream with a RioSocketWrapper object.
 /// </summary>
 /// <param name="socket">a RioSocketWrapper object</param>
 public SocketStream(RioSocketWrapper socket)
 {
     if (socket == null)
     {
         throw new ArgumentNullException("socket");
     }
     streamSocket = socket;
     bufPool = ByteBufPool.UnsafeDefault;
 }
コード例 #4
0
ファイル: ByteBufChunk.cs プロジェクト: zwffff2015/Mobius
        private ByteBufChunk(ByteBufPool pool, IntPtr memory, IntPtr bufId, int segmentSize, int chunkSize)
            : this(pool, segmentSize, chunkSize)
        {
            if (memory == IntPtr.Zero || chunkSize == 0)
            {
                throw new ArgumentNullException("memory", "Must be initialized with a valid heap block.");
            }

            IsUnsafe     = true;
            unsafeMemory = memory;
            this.memory  = null;
            BufId        = bufId;
        }
コード例 #5
0
ファイル: ByteBufChunk.cs プロジェクト: zwffff2015/Mobius
        private ByteBufChunk(ByteBufPool pool, byte[] memory, int segmentSize, int chunkSize)
            : this(pool, segmentSize, chunkSize)
        {
            if (memory == null || chunkSize == 0)
            {
                throw new ArgumentNullException("memory", "Must be initialized with a valid byte array");
            }

            IsUnsafe     = false;
            this.memory  = memory;
            unsafeMemory = IntPtr.Zero;
            BufId        = IntPtr.Zero;
        }
コード例 #6
0
ファイル: ByteBufChunk.cs プロジェクト: qintao1976/Mobius
        private ByteBufChunk(ByteBufPool pool, IntPtr memory, IntPtr bufId, int segmentSize, int chunkSize)
            : this(pool, segmentSize, chunkSize)
        {
            if (memory == IntPtr.Zero || chunkSize == 0)
            {
                throw new ArgumentNullException("memory", "Must be initialized with a valid heap block.");
            }

            IsUnsafe = true;
            unsafeMemory = memory;
            this.memory = null;
            BufId = bufId;
        }
コード例 #7
0
ファイル: ByteBufChunk.cs プロジェクト: qintao1976/Mobius
        private ByteBufChunk(ByteBufPool pool, byte[] memory, int segmentSize, int chunkSize)
            : this(pool, segmentSize, chunkSize)
        {
            if (memory == null || chunkSize == 0)
            {
                throw new ArgumentNullException("memory", "Must be initialized with a valid byte array");
            }

            IsUnsafe = false;
            this.memory = memory;
            unsafeMemory = IntPtr.Zero;
            BufId = IntPtr.Zero;
        }
コード例 #8
0
ファイル: ByteBufChunk.cs プロジェクト: qintao1976/Mobius
        private ByteBufChunk(ByteBufPool pool, int segmentSize, int chunkSize)
        {
            Pool = pool;
            FreeBytes = chunkSize;
            Size = chunkSize;
            this.segmentSize = segmentSize;

            segmentQueue = new Queue<Segment>();
            var numSegment = chunkSize / segmentSize;
            for (var i = 0; i < numSegment; i++)
            {
                segmentQueue.Enqueue(new Segment(i * segmentSize, segmentSize));
            }
        }
コード例 #9
0
ファイル: ByteBufChunk.cs プロジェクト: zwffff2015/Mobius
        private ByteBufChunk(ByteBufPool pool, int segmentSize, int chunkSize)
        {
            Pool             = pool;
            FreeBytes        = chunkSize;
            Size             = chunkSize;
            this.segmentSize = segmentSize;

            segmentQueue = new Queue <Segment>();
            var numSegment = chunkSize / segmentSize;

            for (var i = 0; i < numSegment; i++)
            {
                segmentQueue.Enqueue(new Segment(i * segmentSize, segmentSize));
            }
        }
コード例 #10
0
ファイル: ByteBufChunk.cs プロジェクト: zwffff2015/Mobius
        public static ByteBufChunk NewChunk(ByteBufPool pool, int segmentSize, int chunkSize, bool isUnsafe)
        {
            ByteBufChunk chunk = null;

            if (!isUnsafe)
            {
                chunk = new ByteBufChunk(pool, new byte[chunkSize], segmentSize, chunkSize);
                return(chunk);
            }

            // allocate buffers from process heap
            var token = HeapAlloc(GetProcessHeap(), 0, chunkSize);

            if (token == IntPtr.Zero)
            {
                throw new OutOfMemoryException("Failed to allocate memory by calling HeapAlloc()");
            }

            // register this heap buffer to RIO buffer
            var bufferId = RioNative.RegisterRIOBuffer(token, (uint)chunkSize);

            if (bufferId == IntPtr.Zero)
            {
                FreeToProcessHeap(token);
                throw new Exception(string.Format("Failed to register RIO buffer with error code {0}", Marshal.GetLastWin32Error()));
            }

            try
            {
                chunk    = new ByteBufChunk(pool, token, bufferId, segmentSize, chunkSize);
                token    = IntPtr.Zero;
                bufferId = IntPtr.Zero;
                return(chunk);
            }
            finally
            {
                if (chunk == null && token != IntPtr.Zero)
                {
                    if (bufferId != IntPtr.Zero)
                    {
                        RioNative.DeregisterRIOBuffer(bufferId);
                    }
                    FreeToProcessHeap(token);
                }
            }
        }
コード例 #11
0
ファイル: ByteBufChunk.cs プロジェクト: qintao1976/Mobius
        public static ByteBufChunk NewChunk(ByteBufPool pool, int segmentSize, int chunkSize, bool isUnsafe)
        {
            ByteBufChunk chunk = null;
            if (!isUnsafe)
            {
                chunk = new ByteBufChunk(pool, new byte[chunkSize], segmentSize, chunkSize);
                return chunk;
            }

            // allocate buffers from process heap
            var token = HeapAlloc(GetProcessHeap(), 0, chunkSize);
            if (token == IntPtr.Zero)
            {
                throw new OutOfMemoryException("Failed to allocate memory by calling HeapAlloc()");
            }

            // register this heap buffer to RIO buffer
            var bufferId = RioNative.RegisterRIOBuffer(token, (uint)chunkSize);
            if (bufferId == IntPtr.Zero)
            {
                FreeToProcessHeap(token);
                throw new Exception(string.Format("Failed to register RIO buffer with error code {0}", Marshal.GetLastWin32Error()));
            }

            try
            {
                chunk = new ByteBufChunk(pool, token, bufferId, segmentSize, chunkSize);
                token = IntPtr.Zero;
                bufferId = IntPtr.Zero;
                return chunk;
            }
            finally
            {
                if (chunk == null && token != IntPtr.Zero)
                {
                    if (bufferId != IntPtr.Zero)
                    {
                        RioNative.DeregisterRIOBuffer(bufferId);
                    }
                    FreeToProcessHeap(token);
                }
            }
        }
コード例 #12
0
ファイル: ByteBufChunkTest.cs プロジェクト: jthelin/SparkCLR
 public void CreatePooledBuffer()
 {
     managedBufPool = new ByteBufPool(1024, 2, false);
     unsafeBufPool = new ByteBufPool(1024, 2, true);
 }
コード例 #13
0
 public void CreatePooledBuffer()
 {
     bufPool = new ByteBufPool(1024, 2, false);
 }