Ignore:
Timestamp:
Aug 6, 2024, 10:31:16 PM (2 months ago)
Author:
chronos
Message:
  • Modified: Optimized DeviceMapper read/write handlers calls without case statement.
  • Modified: Use TInt as base data type which can be redefined to different higher integer type. For start it is Int64.
Location:
branches/ByteArray
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ByteArray

    • Property svn:ignore set to
      lib
      heaptrclog.trc
      ByteArray
      ByteArray.dbg
      ByteArray.lps
      ByteArray.res
  • branches/ByteArray/Devices/Memory.pas

    r5 r9  
    44
    55uses
    6   Classes, SysUtils, BigInt, Channel, Device;
     6  Classes, SysUtils, Int, Channel, Device;
    77
    88type
     
    1010  { TMemory }
    1111
    12   TMemory = class(TDevice)
     12  TMemory = class(TChannelDevice)
    1313  private
    14     FSize: Integer;
     14    FSize: TInt;
    1515    FData: PByte;
    16     function GetSize: Integer;
    17     procedure SetSize(AValue: Integer);
     16    function GetSize: TInt;
     17    procedure SetSize(AValue: TInt);
    1818    procedure CheckGrow(Address: Integer);
    1919  public
    20     Position: Integer;
     20    Position: TInt;
    2121    Grow: Boolean;
    2222    procedure Assign(Source: TMemory);
    23     function Read(Address: TBigInt; ASize: TBigIntSize): TBigInt;
    24     function ReadPos(ASize: Byte): TBigInt;
    25     procedure Write(Address: TBigInt; ASize: TBigIntSize; Value: TBigInt);
    26     procedure WritePos(ASize: Byte; Value: TBigInt);
     23    function Read(Address: TInt; ASize: TIntSize): TInt;
     24    function ReadPos(ASize: Byte): TInt;
     25    procedure Write(Address: TInt; ASize: TIntSize; Value: TInt);
     26    procedure WritePos(ASize: Byte; Value: TInt);
    2727    procedure WriteStringPos(Value: string);
    2828    procedure WriteMemoryPos(Memory: TMemory);
    29     function GetAddressCount: Integer; override;
    3029    procedure SetChannel(Channel: TChannel); override;
    3130    procedure SaveToFile(FileName: string);
     31    procedure LoadFromFile(FileName: string);
    3232    procedure FillZero;
    3333    procedure Clear;
    34     property Size: Integer read FSize write SetSize;
     34    property Size: TInt read FSize write SetSize;
    3535    destructor Destroy; override;
    3636  end;
     
    4444{ TMemory }
    4545
    46 function TMemory.GetSize: Integer;
     46function TMemory.GetSize: TInt;
    4747begin
    4848  Result := MemSize(FData);
    4949end;
    5050
    51 procedure TMemory.SetSize(AValue: Integer);
     51procedure TMemory.SetSize(AValue: TInt);
    5252begin
    5353  FSize := AValue;
     
    6868end;
    6969
    70 function TMemory.Read(Address: TBigInt; ASize: TBigIntSize): TBigInt;
     70function TMemory.Read(Address: TInt; ASize: TIntSize): TInt;
    7171begin
    7272  if Address + ASize > FSize then raise Exception.Create(SOutOfRange);
     
    7979end;
    8080
    81 function TMemory.ReadPos(ASize: Byte): TBigInt;
     81function TMemory.ReadPos(ASize: Byte): TInt;
    8282begin
    8383  Result := Read(Position, ASize);
     
    8585end;
    8686
    87 procedure TMemory.Write(Address: TBigInt; ASize: TBigIntSize; Value: TBigInt);
     87procedure TMemory.Write(Address: TInt; ASize: TIntSize; Value: TInt);
    8888begin
    8989  if Address + ASize > FSize then raise Exception.Create(SOutOfRange);
     
    9696end;
    9797
    98 procedure TMemory.WritePos(ASize: Byte; Value: TBigInt);
     98procedure TMemory.WritePos(ASize: Byte; Value: TInt);
    9999begin
    100100  CheckGrow(Position + ASize);
     
    126126end;
    127127
    128 function TMemory.GetAddressCount: Integer;
    129 begin
    130   Result := FSize;
    131 end;
    132 
    133128procedure TMemory.SetChannel(Channel: TChannel);
    134129begin
    135130  Channel.Read := Read;
    136131  Channel.Write := Write;
     132  Channel.GetSize := GetSize;
    137133end;
    138134
     
    168164end;
    169165
     166procedure TMemory.LoadFromFile(FileName: string);
     167var
     168  F: TFileStream;
     169begin
     170  F := TFileStream.Create(FileName, fmOpenRead);
     171  try
     172    if FSize < F.Size then Size := F.Size;
     173    F.Read(FData[0], FSize);
     174  finally
     175    F.Free;
     176  end;
     177end;
     178
    170179end.
    171180
Note: See TracChangeset for help on using the changeset viewer.