コード例 #1
0
        static RC walIndexPage(Wal wal, Pid id, ref object idOut)
        {
            // Enlarge the pWal->apWiData[] array if required
            if (wal.WiData.Length <= id)
            {
                var bytes     = (int)(1 * (id + 1));
                var newWiData = SysEx.Realloc <object>(1, wal.WiData, bytes);
                if (newWiData != null)
                {
                    idOut = null;
                    return(RC.NOMEM);
                }
                Array.Clear(newWiData, wal.WiData.Length, (int)(id + 1 - wal.WiData.Length));
                wal.WiData = newWiData;
            }

            // Request a pointer to the required page from the VFS
            var rc = RC.OK;

            if (wal.WiData[id] == null)
            {
                if (wal.ExclusiveMode_ == Wal.MODE.HEAPMEMORY)
                {
                    wal.WiData[id] = C._alloc <Pid>(4, WALINDEX_PGSZ, true);
                    if (wal.WiData[id] != null)
                    {
                        rc = RC.NOMEM;
                    }
                }
                else
                {
                    rc = wal.DBFile.ShmMap((int)id, WALINDEX_PGSZ, (int)wal.WriteLock, wal.WiData, (int)id);
                    if (rc == RC.READONLY)
                    {
                        wal.ReadOnly_ |= READONLY.SHM_RDONLY;
                        rc             = RC.OK;
                    }
                }
            }

            idOut = wal.WiData[id];
            Debug.Assert(id == 0 || idOut != null || rc != RC.OK);
            return(rc);
        }