コード例 #1
0
        public static IpcCircularBuffer Create(string name, int blockSize, int numberOfBlocks)
        {
            Random r = new Random();
            long   readSemaphoreId  = ((long)r.Next() << 32) + r.Next();
            long   writeSemaphoreId = ((long)r.Next() << 32) + r.Next();

            Section section = new Section(name, blockSize * numberOfBlocks, MemoryProtection.ReadWrite);

            using (SectionView view = section.MapView(BufferHeader.SizeOf))
            {
                BufferHeader header = new BufferHeader
                {
                    BlockSize        = blockSize,
                    NumberOfBlocks   = numberOfBlocks,
                    ReadSemaphoreId  = readSemaphoreId,
                    WriteSemaphoreId = writeSemaphoreId,
                    ReadPosition     = 0, WritePosition = 0
                };

                view.WriteStruct(header);
            }

            return(new IpcCircularBuffer(
                       section,
                       name,
                       new Semaphore(name + "_" + readSemaphoreId.ToString("x"), 0, numberOfBlocks),
                       new Semaphore(name + "_" + writeSemaphoreId.ToString("x"), numberOfBlocks, numberOfBlocks)
                       ));
        }