// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; namespace FASTER.core { /// /// A frame is an in-memory circular buffer of log pages /// internal sealed class GenericFrame : IDisposable { private readonly Record[][] frame; public readonly int frameSize, pageSize; private readonly int recordSize = Utility.GetSize(default(Record)); public GenericFrame(int frameSize, int pageSize) { this.frameSize = frameSize; this.pageSize = pageSize; frame = new Record[frameSize][]; } public void Allocate(int index) { Record[] tmp; if (pageSize % recordSize == 0) tmp = new Record[pageSize / recordSize]; else tmp = new Record[1 + (pageSize / recordSize)]; Array.Clear(tmp, 0, tmp.Length); frame[index] = tmp; } public void Clear(int pageIndex) { Array.Clear(frame[pageIndex], 0, frame[pageIndex].Length); } public ref Key GetKey(long frameNumber, long offset) { return ref frame[frameNumber][offset].key; } public ref Value GetValue(long frameNumber, long offset) { return ref frame[frameNumber][offset].value; } public ref RecordInfo GetInfo(long frameNumber, long offset) { return ref frame[frameNumber][offset].info; } public ref Record[] GetPage(long frameNumber) { return ref frame[frameNumber]; } public void Dispose() { Array.Clear(frame, 0, frame.Length); } } }