Why does it take up so much memory
From: NB (nej_at_tak.dk)
Date: 09/18/04
- Next message: Marco van de Voort: "Re: Why does it take up so much memory"
- Previous message: Marco van de Voort: "Re: Longstanding Delphi bug"
- Next in thread: Marco van de Voort: "Re: Why does it take up so much memory"
- Reply: Marco van de Voort: "Re: Why does it take up so much memory"
- Reply:(deleted message) L D Blake: "Re: Why does it take up so much memory"
- Reply: Tom de Neef: "Re: Why does it take up so much memory"
- Reply: Bruce Roberts: "Re: Why does it take up so much memory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 18 Sep 2004 18:30:11 +0200
When I run this simple application it takes up a huge amount of memory
(in the Task Manager it says more than 100 megabytes). Why is that?
As I see it, 30.000 objects are created containing each 25 characters,
therefor I'd expect for the application to take up around 30.000 x 25 =
750.000 bytes of memory but that's obviously not the case.
Could anyone please help me and explain what I'm doing wrong?
// Test.dpr
program Test;
{$APPTYPE CONSOLE}
uses
SysUtils,
uTest in 'uTest.pas',
uTestList in 'uTestList.pas';
var
FTestList: TTestList;
begin
FTestList := TTestList.Create;
try
FTestList.LoadFromFile('file.txt');
finally
FTestList.Free;
end;
end.
// uTest.pas
unit uTest;
interface
type
TTest = class
private
FValue1: string;
FValue2: string;
FValue3: string;
FValue4: string;
FValue5: string;
public
constructor Create(AValue1, AValue2, AValue3, AValue4, AValue5:
string);
end;
implementation
{ TTest }
constructor TTest.Create(AValue1, AValue2, AValue3, AValue4,
AValue5: string);
begin
FValue1 := AValue1;
FValue2 := AValue1;
FValue3 := AValue1;
FValue4 := AValue1;
FValue5 := AValue1;
end;
end.
// uTestList.pas
unit uTestList;
interface
uses
Classes,
SysUtils,
uTest;
type
TTestList = class
private
FCount: Integer;
FTest: array of TTest;
function Get(AIndex: Integer): TTest;
procedure Put(AIndex: Integer; const ATest: TTest);
public
property Test[AIndex: Integer]: TTest read Get write Put; default;
procedure Add(ATest: TTest);
procedure LoadFromFile(AFileName: string);
end;
implementation
{ TTestList }
procedure TTestList.Add(ATest: TTest);
begin
Inc(FCount);
SetLength(FTest, FCount);
FTest[FCount - 1] := ATest;
end;
function TTestList.Get(AIndex: Integer): TTest;
begin
Result := FTest[AIndex];
end;
procedure TTestList.LoadFromFile(AFileName: string);
var
StringList: TStringList;
Row: Integer;
Line: string;
Value1: string;
Value2: string;
Value3: string;
Value4: string;
Value5: string;
begin
StringList := TStringList.Create;
try
StringList.LoadFromFile(AFileName);
// Approx. 30000 lines.
for Row := 0 to StringList.Count - 1 do
begin
Value1 := Copy(Line, 1, 7);
Value2 := Copy(Line, 8, 3);
Value3 := Copy(Line, 14, 4);
Value4 := Copy(Line, 19, 6);
Value5 := Copy(Line, 49, 5);
Add(
TTest.Create(
Value1,
Value2,
Value3,
Value4,
Value5,
)
);
Write(#13, IntToStr(FCount));
end;
finally
StringList.Free;
end;
end;
procedure TTestList.Put(AIndex: Integer; const ATest: TTest);
begin
FTest[AIndex] := ATest;
end;
end.
- Next message: Marco van de Voort: "Re: Why does it take up so much memory"
- Previous message: Marco van de Voort: "Re: Longstanding Delphi bug"
- Next in thread: Marco van de Voort: "Re: Why does it take up so much memory"
- Reply: Marco van de Voort: "Re: Why does it take up so much memory"
- Reply:(deleted message) L D Blake: "Re: Why does it take up so much memory"
- Reply: Tom de Neef: "Re: Why does it take up so much memory"
- Reply: Bruce Roberts: "Re: Why does it take up so much memory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|