예제 #1
0
        internal void WriteByteArrayTo(IJournalledResource data, long position, byte[] buf, int off, int len)
        {
            if (PARANOID_CHECKS)
            {
                lock (write_lock) {
                    if (write_lock_count == 0)
                    {
                        Console.Out.WriteLine("Write without a Lock!");
                        Console.Out.WriteLine(new ApplicationException().StackTrace);
                    }
                }
            }

            long page_number  = position / page_size;
            int  start_offset = (int)(position % page_size);
            int  to_write     = System.Math.Min(len, page_size - start_offset);

            BMPage page = FetchPage(data, page_number);

            lock (page) {
                try {
                    page.Initialize();
                    page.Write(start_offset, buf, off, to_write);
                } finally {
                    page.Dispose();
                }
            }
            len -= to_write;

            while (len > 0)
            {
                off      += to_write;
                position += to_write;
                ++page_number;
                to_write = System.Math.Min(len, page_size);

                page = FetchPage(data, page_number);
                lock (page) {
                    try {
                        page.Initialize();
                        page.Write(0, buf, off, to_write);
                    } finally {
                        page.Dispose();
                    }
                }
                len -= to_write;
            }
        }
예제 #2
0
        internal void WriteByteTo(IJournalledResource data,
                                  long position, int b)
        {
            if (PARANOID_CHECKS)
            {
                lock (write_lock) {
                    if (write_lock_count == 0)
                    {
                        Console.Out.WriteLine("Write without a Lock!");
                        Console.Out.WriteLine(new ApplicationException().StackTrace);
                    }
                }
            }

            long page_number = position / page_size;

            BMPage page = FetchPage(data, page_number);

            lock (page) {
                try {
                    page.Initialize();
                    page.Write((int)(position % page_size), (byte)b);
                } finally {
                    page.Dispose();
                }
            }
        }