コード例 #1
0
        internal int ReadByteArrayFrom(IJournalledResource data, long position, byte[] buf, int off, int len)
        {
            int  orig_len     = len;
            long page_number  = position / page_size;
            int  start_offset = (int)(position % page_size);
            int  to_read      = System.Math.Min(len, page_size - start_offset);

            BMPage page = FetchPage(data, page_number);

            lock (page) {
                try {
                    page.Initialize();
                    page.Read(start_offset, buf, off, to_read);
                } finally {
                    page.Dispose();
                }
            }

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

                page = FetchPage(data, page_number);
                lock (page) {
                    try {
                        page.Initialize();
                        page.Read(0, buf, off, to_read);
                    } finally {
                        page.Dispose();
                    }
                }
                len -= to_read;
            }

            return(orig_len);
        }
コード例 #2
0
        // ------
        // Buffered access methods.  These are all thread safe methods.  When a page
        // is accessed the page is synchronized so no 2 or more operations can
        // Read/Write from the page at the same time.  An operation can Read/Write to
        // different pages at the same time, however, and this requires thread safety
        // at a lower level (in the IJournalledResource implementation).
        // ------

        internal int ReadByteFrom(IJournalledResource data, long position)
        {
            long page_number = position / page_size;
            int  v;

            BMPage page = FetchPage(data, page_number);

            lock (page) {
                try {
                    page.Initialize();
                    v = ((int)page.Read((int)(position % page_size))) & 0x0FF;
                } finally {
                    page.Dispose();
                }
            }

            return(v);
        }