예제 #1
0
        public static BufferedStreamSegmentFactory Create(Stream source, long length, bool leaveOpen)
        {
            var obj = Cache <BufferedStreamSegmentFactory> .Pop() ?? new BufferedStreamSegmentFactory();

            obj.Init(source, length, leaveOpen);
            return(obj);
        }
예제 #2
0
        public static Message Load(ISegmentFactory segmentFactory)
        {
            var msg = Cache <Message> .Pop() ?? new Message();

            msg.Init(segmentFactory);
            return(msg);
        }
예제 #3
0
        public static BufferSegmentFactory Create(byte[] buffer, int offset = 0, int count = -1, int defaultSegmentWords = DefaultSegmentWords)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException();
            }
            if (defaultSegmentWords <= 0)
            {
                throw new ArgumentOutOfRangeException("segmentWords");
            }
            if (offset < 0 || offset >= buffer.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (count < 0)
            {
                count = buffer.Length - offset;
            }
            else if (offset + count > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            var state = Cache <BufferSegmentFactory> .Pop() ?? new BufferSegmentFactory();

            state.Init(buffer, offset, count, defaultSegmentWords);
            return(state);
        }
예제 #4
0
 public static PointerSegment Create(bool free)
 {
     if (free)
     {
         return(Cache <PointerOwningSegment> .Pop() ?? new PointerOwningSegment());
     }
     return(Cache <PointerSegment> .Pop() ?? new PointerSegment());
 }
        public static MemoryMappedFileSegmentFactory Open(MemoryMappedFile file, long offset = 0, long length = -1,
                                                          MemoryMappedFileAccess access      = MemoryMappedFileAccess.Read, int defaultSegmentWords = DefaultSegmentWords, bool leaveOpen = false)
        {
            MemoryMappedFileSegmentFactory obj = null;

            try
            {
                obj = Cache <MemoryMappedFileSegmentFactory> .Pop() ?? new MemoryMappedFileSegmentFactory();

                obj.Init(file, offset, length, access, defaultSegmentWords, leaveOpen);
                var tmp = obj;
                obj = null; // to avoid finally
                return(tmp);
            }
            finally
            {
                Cache <MemoryMappedFileSegmentFactory> .Push(obj);
            }
        }
        public static MemoryMappedFileSegmentFactory Open(string path, long offset      = 0, long length = -1,
                                                          MemoryMappedFileAccess access = MemoryMappedFileAccess.Read, int defaultSegmentWords = DefaultSegmentWords)
        {
            MemoryMappedFileSegmentFactory obj = null;

            try
            {
                obj = Cache <MemoryMappedFileSegmentFactory> .Pop() ?? new MemoryMappedFileSegmentFactory();

                obj.Init(path, 0, length, FileMode.Open, access, defaultSegmentWords);
                var tmp = obj;
                obj = null; // to avoid finally
                return(tmp);
            }
            finally
            {
                Cache <MemoryMappedFileSegmentFactory> .Push(obj);
            }
        }
예제 #7
0
 static Textizer Create()
 {
     return(Cache <Textizer> .Pop() ?? new Textizer());
 }