Beispiel #1
0
        public void WriteHeader()
        {
            StockHeader header = new StockHeader();

            header.SharedMemorySize = SharedMemorySize;
            header.UsedMemorySize   = UsedMemorySize;
            header.FreeMemorySize   = FreeMemorySize;
            header.ItemCapacity     = ItemCapacity;
            header.ItemCount        = ItemCount;
            header.ItemSize         = ItemSize;
            header.StockId          = StockId;
            header.SectorId         = SectorId;
            header.Shutdown         = 0;
            View.Write(HeaderOffset, header);
        }
Beispiel #2
0
        public void ReadHeader()
        {
            object _header = new object();

            View.Read(HeaderOffset, _header, typeof(StockHeader));
            StockHeader header     = (StockHeader)_header;
            int         headerSize = Marshal.SizeOf(typeof(StockHeader));

            BufferSize   = header.SharedMemorySize - headerSize;
            UsedSize     = header.UsedMemorySize - headerSize;
            FreeSize     = header.FreeMemorySize - headerSize;
            ItemCapacity = header.ItemCapacity;
            ItemSize     = header.ItemSize;
            ItemCount    = header.ItemCount;
            StockId      = header.StockId;
            SectorId     = header.SectorId;
        }
Beispiel #3
0
        public void InitHeader()
        {
            if (!IsOwnerOfSharedMemory)
            {
                return;
            }

            StockHeader header = new StockHeader();

            header.SharedMemorySize = SharedMemorySize;
            header.UsedMemorySize   = Marshal.SizeOf(typeof(StockHeader));
            header.FreeMemorySize   = SharedMemorySize - header.UsedMemorySize;
            header.ItemSize         = (ItemType != null && ItemSize > 0) ? ItemSize : -1;
            header.ItemCapacity     = (ItemType != null && ItemSize > 0) ? (header.FreeMemorySize / ItemSize) : -1;
            header.ItemCount        = -1;
            header.Shutdown         = 0;
            View.Write(HeaderOffset, header);
        }
Beispiel #4
0
        public void PreReadHeader()
        {
            using (MemoryMappedViewAccessor headerView =
                       Mmf.CreateViewAccessor(0, HeaderOffset + Marshal.SizeOf(typeof(StockHeader)), MemoryMappedFileAccess.Read))
            {
                byte *headerPtr = null;

                headerView.SafeMemoryMappedViewHandle.AcquireIntPtr(ref headerPtr);
                StockHeader *_header    = (StockHeader *)(headerPtr + HeaderOffset);
                StockHeader  header     = (StockHeader)Marshal.PtrToStructure((IntPtr)_header, typeof(StockHeader));
                int          headerSize = Marshal.SizeOf(typeof(StockHeader));
                BufferSize   = header.SharedMemorySize - headerSize;
                UsedSize     = header.UsedMemorySize - headerSize;
                FreeSize     = header.FreeMemorySize - headerSize;
                ItemCapacity = header.ItemCapacity;
                ItemSize     = header.ItemSize;
                ItemCount    = header.ItemCount;
                StockId      = header.StockId;
                SectorId     = header.SectorId;
                headerView.SafeMemoryMappedViewHandle.ReleaseIntPtr();
            }
        }