示例#1
0
 public WavPlayer(IBufferAllocator <byte> bufferAllocator)
 {
     this.bufferAllocator = bufferAllocator;
     WaveOut        = new WaveOut();
     CurrentSegment = null;
     Position       = 0;
 }
示例#2
0
 internal BinaryResponse(IBufferAllocator allocator)
 {
     this.allocator  = allocator;
     StatusCode      = -1;
     header          = allocator.Take(Protocol.HeaderLength);
     remainingHeader = Protocol.HeaderLength;
 }
		public static PooledSegment GetBytes(IBufferAllocator allocator, bool value)
		{
			var retval = new PooledSegment(allocator, 1);
			retval.Array[0] = value ? TRUE : FALSE;

			return retval;
		}
		internal BinaryResponse(IBufferAllocator allocator)
		{
			this.allocator = allocator;
			StatusCode = -1;
			header = allocator.Take(Protocol.HeaderLength);
			remainingHeader = Protocol.HeaderLength;
		}
示例#5
0
        public static ByteBuffer GetBytes(IBufferAllocator allocator, byte value)
        {
            var retval = new ByteBuffer(allocator, 1);

            retval.Array[0] = value;

            return(retval);
        }
示例#6
0
        public ByteBuffer Clone()
        {
            var retval = new ByteBuffer(owner, Array, Length);

            owner = null;

            return(retval);
        }
示例#7
0
 public void Dispose()
 {
     if (owner != null)
     {
         owner.Return(Array);
         owner = null;
     }
 }
示例#8
0
        public Key Clone()
        {
            var retval = new Key(owner, Array, Length);

            owner = null;

            return(retval);
        }
        public static PooledSegment GetBytes(IBufferAllocator allocator, bool value)
        {
            var retval = new PooledSegment(allocator, 1);

            retval.Array[0] = value ? TRUE : FALSE;

            return(retval);
        }
示例#10
0
 public MNISTDataSet(string trainImageFile, string trainLabelFile, string testImageFile, string testLabelFile, IBufferAllocator allocator)
 {
     this.trainImageFile = trainImageFile;
     this.trainLabelFile = trainLabelFile;
     this.testImageFile  = testImageFile;
     this.testLabelFile  = testLabelFile;
     this.allocator      = allocator;
 }
示例#11
0
        public static ByteBuffer GetBytes(IBufferAllocator allocator, bool value)
        {
            var retval = new ByteBuffer(allocator, 1);

            retval.Array[0] = value ? TRUE : FALSE;

            return(retval);
        }
示例#12
0
		public void Dispose()
		{
			if (allocator != null)
			{
				allocator.Return(array);
				array = null;
				allocator = null;
			}
		}
示例#13
0
        public PooledSegment(IBufferAllocator allocator, int count)
        {
            Require.NotNull(allocator, "allocator");
            Require.That(count >= 0, "count must be >= 0");

            this.allocator = allocator;
            this.array     = allocator.Take(count);
            this.count     = count;
        }
示例#14
0
        /// <summary>
        /// Unowned buffer
        /// </summary>
        public PooledSegment(byte[] array, int count)
        {
            Require.NotNull(array, "array");
            Require.That(count >= 0, "count must be >= 0");

            this.allocator = null;
            this.array     = array;
            this.count     = count;
        }
示例#15
0
 public MemcachedCluster(IEnumerable <IPEndPoint> endpoints, IBufferAllocator allocator,
                         INodeLocator locator, IReconnectPolicy reconnectPolicy, IFailurePolicy failurePolicy,
                         Func <ISocket> socketFactory)
     : base(endpoints, locator, reconnectPolicy)
 {
     this.allocator     = allocator;
     this.failurePolicy = failurePolicy;
     this.socketFactory = socketFactory;
 }
		public MemcachedCluster(IEnumerable<IPEndPoint> endpoints, IBufferAllocator allocator,
			INodeLocator locator, IReconnectPolicy reconnectPolicy, IFailurePolicy failurePolicy,
			Func<ISocket> socketFactory)
			: base(endpoints, locator, reconnectPolicy)
		{
			this.allocator = allocator;
			this.failurePolicy = failurePolicy;
			this.socketFactory = socketFactory;
		}
		/// <summary>
		/// Unowned buffer
		/// </summary>
		public PooledSegment(byte[] array, int count)
		{
			Require.NotNull(array, "array");
			Require.That(count >= 0, "count must be >= 0");

			this.allocator = null;
			this.array = array;
			this.count = count;
		}
		public PooledSegment(IBufferAllocator allocator, int count)
		{
			Require.NotNull(allocator, "allocator");
			Require.That(count >= 0, "count must be >= 0");

			this.allocator = allocator;
			this.array = allocator.Take(count);
			this.count = count;
		}
示例#19
0
        public ByteBuffer(IBufferAllocator owner, byte[] array, int length)
        {
            Require.NotNull(array, nameof(array));
            Require.That(length >= 0, $"{nameof(length)} must be >= 0");

            this.owner = owner;
            Array      = array;
            Length     = length;
        }
示例#20
0
 public void Dispose()
 {
     if (allocator != null)
     {
         allocator.Return(array);
         array     = null;
         allocator = null;
     }
 }
示例#21
0
        public AsyncServerSocket(IPEndPoint listenEndpoint, IChannelInitialiser channelInitialiser)
        {
            this._listenEndpoint     = listenEndpoint;
            this._channelInitialiser = channelInitialiser;

            this._bufferAllocator = new PooledBufferAllocator(MaxSimultaneousConnections * 2, ChannelBufferSize);

            this._acceptArgsPool = new SocketAsyncEventArgsPool(MaxSimultaneousAcceptOperations, CreateAcceptEventArgs);
            this._ioArgsPool     = new SocketAsyncEventArgsPool(MaxSimultaneousConnections, CreateIoEventArgs);
        }
示例#22
0
        public Key(IBufferAllocator allocator, byte[] array, int length)
        {
            Require.NotNull(allocator, "allocator");
            Require.NotNull(array, "array");
            Require.That(length >= 0, "length must be >= 0");

            this.allocator = allocator;
            this.array     = array;
            this.length    = length;
        }
示例#23
0
        public ConnectionIoActor(IWorkScheduler worker, IBufferAllocator bufferAllocator)
        {
            _sendQueue    = new BlockingQueue <IOState>();
            _receiveQueue = new BlockingQueue <IOState>();

            _bufferAllocator = bufferAllocator;
            _worker          = worker;
            _worker.QueueForever(SendEnqueued, 1.Milliseconds());
            _worker.QueueForever(ReceiveEnqueued, 1.Milliseconds());
        }
示例#24
0
        public Key(IBufferAllocator allocator, int length)
            : this()
        {
            Require.NotNull(allocator, "allocator");
            Require.That(length >= 0, "length must be >= 0");

            this.allocator = allocator;
            this.length    = length;
            array          = allocator.Take(length);
        }
示例#25
0
 public FFNNetLayer(int neurons, int weightsPerNeurons, IBufferAllocator allocator, Type precission)
 {
     this.neurons           = neurons;
     this.weightsPerNeurons = weightsPerNeurons;
     this.elementSize       = Marshal.SizeOf(precission);
     weights = allocator.AllocateBuffer(neurons * WeightsPerNeurons * elementSize);
     outputs = allocator.AllocateBuffer(neurons * elementSize);
     biases  = allocator.AllocateBuffer(neurons * elementSize);
     lambdas = allocator.AllocateBuffer(neurons * elementSize);
 }
示例#26
0
		public Key(IBufferAllocator allocator, int length)
			: this()
		{
			Require.NotNull(allocator, "allocator");
			Require.That(length >= 0, "length must be >= 0");

			this.allocator = allocator;
			this.length = length;
			array = allocator.Take(length);
		}
		public static Key EncodeKey(IBufferAllocator allocator, string key)
		{
			if (String.IsNullOrEmpty(key)) return Key.Empty;

			var max = Encoding.UTF8.GetMaxByteCount(key.Length);
			var buffer = allocator.Take(max);
			var count = Encoding.UTF8.GetBytes(key, 0, key.Length, buffer, 0);

			return new Key(allocator, buffer, count);
		}
示例#28
0
        public ConnectionIoActor(IWorkScheduler worker, IBufferAllocator bufferAllocator)
        {
            _sendQueue = new BlockingQueue<IOState>();
            _receiveQueue = new BlockingQueue<IOState>();

            _bufferAllocator = bufferAllocator;
            _worker = worker;
            _worker.QueueForever(SendEnqueued, 1.Milliseconds());
            _worker.QueueForever(ReceiveEnqueued, 1.Milliseconds());
        }
示例#29
0
        public Key(IBufferAllocator owner, byte[] array, int length)
        {
            Require.NotNull(array, nameof(array));
            Require.Value(nameof(length), length >= 0, $"{nameof(length)} must be >= 0");
            Require.Value(nameof(length), length <= array.Length, $"{nameof(length)} cannot be greater than the size of the array");

            this.owner = owner;
            Array      = array;
            Length     = length;
        }
示例#30
0
		public Key(IBufferAllocator allocator, byte[] array, int length)
		{
			Require.NotNull(allocator, "allocator");
			Require.NotNull(array, "array");
			Require.That(length >= 0, "length must be >= 0");

			this.allocator = allocator;
			this.array = array;
			this.length = length;
		}
示例#31
0
        private byte[] byteArray;     // helper for Read/WriteByte

        public PooledMemoryStream(IBufferAllocator allocator)
        {
            this.allocator = allocator;

            chunks       = new List <byte[]>();
            lengths      = new List <int>();
            currentChunk = EmptyChunk;
            currentIndex = -1;

            byteArray = new byte[1];
        }
示例#32
0
 public FilePartSource(Stream fileStream, IMD5HashProvider hashProvider, IBufferAllocator bufferAllocator, long offset)
 {
     fileHash             = hashProvider;
     this.fileStream      = fileStream;
     this.bufferAllocator = bufferAllocator;
     fileLength           = fileStream.Length;
     streamPosition       = offset;
     this.fileStream.Seek(streamPosition, SeekOrigin.Begin);
     partCount = 0;
     HasMore   = true;
 }
		private byte[] byteArray; // helper for Read/WriteByte

		public PooledMemoryStream(IBufferAllocator allocator)
		{
			this.allocator = allocator;

			chunks = new List<byte[]>();
			lengths = new List<int>();
			currentChunk = EmptyChunk;
			currentIndex = -1;

			byteArray = new byte[1];
		}
		public unsafe static PooledSegment GetBytes(IBufferAllocator allocator, short value)
		{
			var retval = new PooledSegment(allocator, 2);

			fixed (byte* ptr = retval.Array)
			{
				ptr[0] = (byte)value;
				ptr[1] = (byte)(value >> 8);
			}

			return retval;
		}
示例#35
0
        public unsafe static ByteBuffer GetBytes(IBufferAllocator allocator, short value)
        {
            var retval = new ByteBuffer(allocator, 2);

            fixed(byte *ptr = retval.Array)
            {
                ptr[0] = (byte)value;
                ptr[1] = (byte)(value >> 8);
            }

            return(retval);
        }
示例#36
0
 public FilePartConfig()
 {
     InitialPartSize             = 512 * 1024;
     MaxPartSize                 = 8 * 1024 * 1024;
     MinPartSize                 = 4 * 1024;
     MinFileSizeForMultithreaded = 8 * 1024 * 1024;
     TargetPartUploadTime        = TimeSpan.FromSeconds(15);
     MaxPartSizeIncreaseFactor   = 8;
     MaxPartSizeDecreaseFactor   = 2;
     PartRetryCount              = 1;
     BufferAllocator             = new PooledBufferAllocator();
 }
            public StoreRequest(IBufferAllocator allocator, OpCode operation, CacheItem value, uint expires)
                : base(allocator, operation, ExtraLength)
            {
                var extra  = Extra.Array;
                var offset = Extra.Offset;

                // store the extra values
                NetworkOrderConverter.EncodeUInt32(value.Flags, extra, offset);
                NetworkOrderConverter.EncodeUInt32(expires, extra, offset + 4);

                Data = value.Segment.AsArraySegment();
            }
 public IAsyncResult BeginRequest <T>(
     string serviceName,
     string methodName,
     Message <T> input,
     IBufferAllocator allocator,
     AsyncCallback userCallback,
     object stateObject)
     where T : IBondSerializable, new()
 {
     m_scenario.FailIfNecessary(methodName);
     m_scenario.HandleMessage(input);
     return(m_client.BeginRequest(serviceName, methodName, input, allocator, userCallback, stateObject));
 }
        public static Key EncodeKey(IBufferAllocator allocator, string key)
        {
            if (String.IsNullOrEmpty(key))
            {
                return(Key.Empty);
            }

            var max    = Encoding.UTF8.GetMaxByteCount(key.Length);
            var buffer = allocator.Take(max);
            var count  = Encoding.UTF8.GetBytes(key, 0, key.Length, buffer, 0);

            return(new Key(allocator, buffer, count));
        }
示例#40
0
        public static ByteBuffer AsByteBuffer(this ArraySegment <byte> segment, IBufferAllocator allocator = null)
        {
            if (segment.Offset == 0)
            {
                return(new ByteBuffer(null, segment.Array, segment.Count));
            }

            var target = allocator == null ? new byte[segment.Count] : allocator.Take(segment.Count);

            Buffer.BlockCopy(segment.Array, segment.Offset, target, 0, segment.Count);

            return(new ByteBuffer(allocator, target, segment.Count));
        }
        public static ByteBuffer GetBytes(IBufferAllocator allocator, short value)
        {
            var retval = new ByteBuffer(allocator, allocator.Take(2), 2);

            var ptr = retval.Array;

            {
                ptr[0] = (byte)value;
                ptr[1] = (byte)(value >> 8);
            }

            return(retval);
        }
		protected override void Dispose(bool disposing)
		{
			base.Dispose(disposing);

			if (allocator != null)
			{
				foreach (var chunk in chunks)
					allocator.Return(chunk);

				chunks = null;
				currentChunk = null;
				allocator = null;
			}
		}
		protected BinaryRequest(IBufferAllocator allocator, byte commandCode, byte extraLength)
		{
			this.allocator = allocator;

			Operation = commandCode;
			CorrelationId = unchecked((uint)Interlocked.Increment(ref InstanceCounter)); // request id

			// prealloc header so that the extra data can be placed into the same buffer
			headerLength = Protocol.HeaderLength + extraLength;
			header = allocator.Take(headerLength);

			if (extraLength > 0)
				Extra = new ArraySegment<byte>(header, Protocol.HeaderLength, extraLength);
		}
		/// <summary>
		/// Unowned buffer
		/// </summary>
		public static PooledSegment From(ArraySegment<byte> source, IBufferAllocator allocator = null)
		{
			var c = source.Count;
			if (source.Offset == 0)
				return new PooledSegment(source.Array, c);

			var retval = allocator == null
							? new PooledSegment(new byte[c], c)
							: new PooledSegment(allocator, c);

			Buffer.BlockCopy(source.Array, source.Offset, retval.array, 0, c);

			return retval;
		}
示例#45
0
        public static FFNNet FromDTO(FFNNetDTO dto, IBufferAllocator allocator)
        {
            FFNNet net = new FFNNet();

            net.allocator  = allocator;
            net.precission = dto.Precission;
            net.layers     = new FFNNetLayer[dto.Layers.Length];

            for (int i = 0; i < net.layers.Length; i++)
            {
                net.layers[i] = FFNNetLayer.FromDTO(dto.Layers[i], allocator, net.precission);
            }
            return(net);
        }
		public unsafe static PooledSegment GetBytes(IBufferAllocator allocator, decimal value)
		{
			// should use 'internal static void GetBytes(decimal d, byte[] buffer)'
			int v;
			var tmp = Decimal.GetBits(value);
			var retval = new PooledSegment(allocator, 16);

			const int I_0 = 0;
			const int I_1 = 4;
			const int I_2 = 8;
			const int I_3 = 12;

			fixed (byte* ptr = retval.Array)
			{
				v = tmp[0];
				ptr[0 + I_0] = (byte)v;
				ptr[1 + I_0] = (byte)(v >> 8);
				ptr[2 + I_0] = (byte)(v >> 16);
				ptr[3 + I_0] = (byte)(v >> 24);

				v = tmp[1];
				ptr[0 + I_1] = (byte)v;
				ptr[1 + I_1] = (byte)(v >> 8);
				ptr[2 + I_1] = (byte)(v >> 16);
				ptr[3 + I_1] = (byte)(v >> 24);

				v = tmp[2];
				ptr[0 + I_2] = (byte)v;
				ptr[1 + I_2] = (byte)(v >> 8);
				ptr[2 + I_2] = (byte)(v >> 16);
				ptr[3 + I_2] = (byte)(v >> 24);

				v = tmp[3];
				ptr[0 + I_3] = (byte)v;
				ptr[1 + I_3] = (byte)(v >> 8);
				ptr[2 + I_3] = (byte)(v >> 16);
				ptr[3 + I_3] = (byte)(v >> 24);
			}

			return retval;
		}
示例#47
0
        public BinaryLogSerilizer(BufferAndSubmiterTuple logentry,BufferAndSubmiterTuple definitions, BufferAndSubmiterTuple stringCache)
        {
            m_logEntrySubmiter = logentry.SubmitLogEntry;
            m_logEntryBufferAllocator = logentry.BufferAllocator;
            m_stringCacheBufferAllocator = stringCache.BufferAllocator;
            m_stringCacheSubmiter = stringCache.SubmitLogEntry;
            m_definitionBufferAllocator = definitions.BufferAllocator;
            m_definitionSubmiter = definitions.SubmitLogEntry;

            m_streamLogBinaryPackager = new StreamLogBinaryPackager();
            m_streamLogBinaryPackager.StringChached += OnStringChached;
            m_streamLogBinaryPackager.PackageRegistered += OnPackageRegistered;

            m_streamLogBinaryPackager.RegisterDefinition(new LogEntryPackageDefinition());
            m_streamLogBinaryPackager.RegisterDefinition(new StringLogTitlePackageDefinition());
            m_streamLogBinaryPackager.RegisterDefinition(new CustomStringLogTitlePackageDefinition());
            m_streamLogBinaryPackager.RegisterDefinition(new OpenLogScopeTitlePackageDefinition());
            m_streamLogBinaryPackager.RegisterDefinition(new PackageDefinition<CloseLogScopeTitle>());
            m_streamLogBinaryPackager.RegisterDefinition(new StringCachePackageDefinition());

            m_streamLogBinaryPackager.RegisterDefinition(new ObjectPackageDefinition());
        }
		public NullKeyTransformer(IBufferAllocator allocator)
		{
			this.allocator = allocator;
		}
示例#49
0
 protected PeerStreamReader(Stream stream, IBufferAllocator bufferAllocator)
 {
     Stream = stream;
     BufferAllocator = bufferAllocator;
 }
示例#50
0
 public PeerStreamWriter(Stream stream, IBufferAllocator bufferAllocator)
 {
     Stream = stream;
     BufferAllocator = bufferAllocator;
 }
		public unsafe static PooledSegment GetBytes(IBufferAllocator allocator, long value)
		{
			var retval = new PooledSegment(allocator, 8);

			fixed (byte* ptr = retval.Array)
			{
				ptr[0] = (byte)value;
				ptr[1] = (byte)(value >> 8);
				ptr[2] = (byte)(value >> 16);
				ptr[3] = (byte)(value >> 24);
				ptr[4] = (byte)(value >> 32);
				ptr[5] = (byte)(value >> 40);
				ptr[6] = (byte)(value >> 48);
				ptr[7] = (byte)(value >> 56);
			}

			return retval;
		}
		public static PooledSegment GetBytes(IBufferAllocator allocator, uint value)
		{
			return GetBytes(allocator, (int)value);
		}
		public static PooledSegment GetBytes(IBufferAllocator allocator, ulong value)
		{
			return GetBytes(allocator, (long)value);
		}
		public unsafe static PooledSegment GetBytes(IBufferAllocator allocator, float value)
		{
			return GetBytes(allocator, *(int*)(&value));
		}
		public unsafe static PooledSegment GetBytes(IBufferAllocator allocator, double value)
		{
			return GetBytes(allocator, *(long*)(&value));
		}
		public static PooledSegment GetBytes(IBufferAllocator allocator, char value)
		{
			return GetBytes(allocator, (short)value);
		}
		public Murmur32KeyTransformer(IBufferAllocator allocator) : base(allocator)
		{
			this.allocator = allocator;
		}
示例#58
0
 public BufferAndSubmiterTuple(ISubmitEntry<IRawData> entry,IBufferAllocator bufferAllocator)
 {
     SubmitLogEntry = entry;
     BufferAllocator = bufferAllocator;
 }
		public BinaryRequest(IBufferAllocator allocator, OpCode operation, byte extraLength = 0)
			: this(allocator, (byte)operation, extraLength) { }
		public MemcachedOperationFactory(IBufferAllocator allocator)
		{
			this.allocator = allocator;
		}