コード例 #1
0
ファイル: PageBuffer.cs プロジェクト: PLCnext/PLCnext_CLI
        /// <summary>
        /// Initializes a new instance of the <see cref="PageBuffer"/> class.
        /// </summary>
        /// <param name="options">The options.</param>
        public PageBuffer(PageBufferOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.BufferType == PageBufferType.File)
            {
                tempFile = System.IO.Path.GetTempFileName();
                stream   = new FileStream(
                    System.IO.Path.GetTempFileName(),
                    FileMode.Create,
                    FileAccess.ReadWrite,
                    FileShare.None,
                    4096,
                    FileOptions.DeleteOnClose);

                if (options.EnableDoubleBuffer)
                {
                    stream = new BufferedStream(stream);
                }
            }
            else
            {
                tempFile = string.Empty;
                stream   = new MemoryStream();
                stream.SetLength(options.Capacity);
            }

            buddyAllocactor = new BuddyAllocator(stream, options.Capacity, options.MinimalCapacity);
        }
コード例 #2
0
        public static PageStreamFactory CreateDefault(int gbCapacity = 1)
        {
            const int         kb = 1024;
            const int         mb = kb * 1024;
            const long        gb = mb * 1024;
            PageBufferOptions pageBufferOptions =
                new PageBufferOptions(gbCapacity * gb, kb)
            {
                BufferType         = PageBufferType.File,
                EnableDoubleBuffer = false
            };
            PageBuffer        pageBuffer    = new PageBuffer(pageBufferOptions);
            PageStreamFactory streamFactory = new PageStreamFactory(pageBuffer);

            return(streamFactory);
        }