76

Re: Optimization of byte reading and comparing of two binary files

Bellic wrote:

0,08 seconds !!!!

well here, at last real time.

77

Re: Optimization of byte reading and comparing of two binary files

Bellic wrote:

Received time of a cycle - 0,08 seconds !!!!
It perhaps the Champion

mmf still try. To what this fuss with selection of storage and reading of files:-Q

78

Re: Optimization of byte reading and comparing of two binary files

vavan;
mmf not faster

79

Re: Optimization of byte reading and comparing of two binary files

vavan wrote:

mmf still try. To what this fuss with selection of storage and reading of files:-Q

Well here, came!... 8-o
Wanted was to pass already to some "interiors" of Real procedure,  for example "SStroka: = SStroka + AnsiChar (ISimvol);" and other, but here was vavan and demanded justice!... smile))
I will answer:
1 . Here it will just seems to me with " MMF "  more fuss!?
2 . Not absolutely this " MMF " and its Pointery are pleasant to me, owing to my feeble knowledge!... (
Well, MMF so MMF... I Will try, but not  that I will consult!

80

Re: Optimization of byte reading and comparing of two binary files

SOFT FOR YOU wrote:

mmf not faster

even if and so that in the didactic purposes to the keen can appear interesno:-Q

81

Re: Optimization of byte reading and comparing of two binary files

Bellic wrote:

here was vavan and I demanded justice

I do not insist, I am sorry

82

Re: Optimization of byte reading and comparing of two binary files

vavan wrote:

I do not insist, I am sorry

Now you will be !!!.))))))
(Sorry for familiarity!)

83

Re: Optimization of byte reading and comparing of two binary files

Bellic wrote:

Now you will be

not, after me and that that already worked ceases:)))

84

Re: Optimization of byte reading and comparing of two binary files

vavan wrote:

not, after me and that that already worked ceases:)))

Then you can faster than I alter the Test example? The code above is available!...)))
But to break the it will not be a pity!.)))

85

Re: Optimization of byte reading and comparing of two binary files

Guys, prompt ...
Took for a basis the following code:

unit Unit1;
interface
uses
Winapi. Windows, Winapi. Messages, System. SysUtils, System. Variants, System. Classes, Vcl. Graphics;
Vcl. Controls, Vcl. Forms, Vcl. Dialogs, Vcl. StdCtrls;
type
TForm1 = class (TForm)
Button1: TButton;
procedure Button1Click (Sender: TObject);
private
{Private declarations}
public
{Public declarations}
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click (Sender: TObject);
var file _, map: dword;
buf: pointer;
begin
file_: = CreateFile (' f:\apm_original.bin ', GENERIC_READ, FILE_SHARE_READ;
nil, OPEN_EXISTING, 0, 0);
if file_ <> INVALID_HANDLE_VALUE then
try
map: = CreateFileMapping (file _, nil, PAGE_READWRITE, 0, 0, nil);//this line map=0!!!
if map <> 0 then
try
buf: = MapViewOfFile (map, FILE_MAP_ALL_ACCESS, 0, 0, 0);
if buf <> nil then
try
//now here you have your file1.txt in memory
//beginning at pointer "buf"
finally UnmapViewOfFile (buf) end;
finally CloseHandle (map) end;
finally CloseHandle (file _) end;
end;
end.

Further the marked line - does not go, therefore as map=0!
What it is necessary to correct?
Can still where errors are here?
...
Well and a secret question - after Mappinga how to read bytes and to move ?

86

Re: Optimization of byte reading and comparing of two binary files

Bellic wrote:

Further the marked line - does not go, therefore as map=0!
What it is necessary to correct?

In line:

map: = CreateFileMapping (file _, nil, PAGE_READWRITE, 0, 0, nil);

Replaced parameter PAGE_READWRITE on PAGE_READONLY and map became nonzero!
And what - it was impossible to leave???

87

Re: Optimization of byte reading and comparing of two binary files

Bellic;
Simply you a file opened well reading. It is possible rid-rajt if is  the rights to a file

88

Re: Optimization of byte reading and comparing of two binary files

Bellic;
MMF it is useful, in particular, if files big so them is problematic to load entirely in storage. If it is possible to load in storage, for example files in the size in some tens megabytes easier and probably faster and to make, here is how in a variant with TBytes.

89

Re: Optimization of byte reading and comparing of two binary files

s62 wrote:

Bellic;
MMF it is useful, in particular, if files big so them is problematic to load entirely in storage. If it is possible to load in storage, for example files in the size in some tens megabytes easier and probably faster and to make, here is how in a variant with TBytes.

Guys, it is wait a moment sensitive!
Late already "to drink Borzhomi"! - the Code is almost ready,  tiny remained!   and  at it!.)))

90

Re: Optimization of byte reading and comparing of two binary files

... A head broke already. (((

OriginalBuf//It is ready Pointer on the Map-file
PO: = PByte (OriginalBuf);

How now to consider byte ISimvol on this Pointeru later to make an increment:

Inc (PO);

is shorter - it was tangled!!!

91

Re: Optimization of byte reading and comparing of two binary files

All!
Understood itself...)))

92

Re: Optimization of byte reading and comparing of two binary files

Mmf will not be faster. 10 Mb it in the modern conditions are a little even on telephono-tablets. With a view of convenience and simplicity, it is better reading in TBytes and it will be restricted. Look the remaining.

93

Re: Optimization of byte reading and comparing of two binary files

On a basis "Memory-Mapped File" the following code turned out:
[spoiler]

procedure TMainForm. TestButtonClick (Sender: TObject);
var
SizeOriginal: Integer;
SizePereveden: Integer;
BOriginal: TBytes;
BPereveden: TBytes;
MOriginal, OriginalMap: DWORD;
MPereveden, PerevedenMap: DWORD;
OriginalBuf, PerevedenBuf: Pointer;
pCurrent: Pointer;
PO: PByte;
PP: PByte;
begin
try
MainMemo. Lines. Clear;
//we Read out names of files from editing Fields (were probably edited!)
FullOriginalFileName: = FileBinOriginalEdit. Text;
FullPerevedenFileName: = FileBinPerevedenEdit. Text;
FullPerevodFileName: = DirPerevodEdit. Text + PerevodFileNameEdit. Text;
FOriginal: = TFileStream. Create (FullOriginalFileName, fmOpenRead, fmShareDenyNone);
FPereveden: = TFileStream. Create (FullPerevedenFileName, fmOpenRead, fmShareDenyNone);
SizeOriginal: = FOriginal. Size;
SizePereveden: = FPereveden. Size;
if SizeOriginal <> SizePereveden then
begin
ShowMessage (' Lengths of BIN-files are not equal! ' + #10#13 +
' Continuation of process of handling - Is impossible! ');
Exit;
end;
MOriginal: = CreateFile (pChar (FullOriginalFileName), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0,0);
MPereveden: = CreateFile (pChar (FullPerevedenFileName), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0,0);
if (MOriginal <> INVALID_HANDLE_VALUE) and (MPereveden <> INVALID_HANDLE_VALUE) then
try
OriginalMap: = CreateFileMapping (MOriginal, nil, PAGE_READONLY, 0, 0, nil);
PerevedenMap: = CreateFileMapping (MPereveden, nil, PAGE_READONLY, 0, 0, nil);
if (OriginalMap <> 0) and (PerevedenMap <> 0) then
try
OriginalBuf: = MapViewOfFile (OriginalMap, FILE_MAP_READ, 0, 0, 0);
PerevedenBuf: = MapViewOfFile (PerevedenMap, FILE_MAP_READ, 0, 0, 0);
if (OriginalBuf <> nil) and (PerevedenBuf <> nil) then
try
AddressFiles: = 0;
StartTime: = Now;//we Fix Start time
PO: = PByte (OriginalBuf);
PP: = PByte (PerevedenBuf);
while AddressFiles <= SizeOriginal-1 do
begin
ISimvol: = Byte (PO ^);
PSimvol: = Byte (PP ^);
Inc (PO);
Inc (PP);
Inc (AddressFiles);
//we Search for coincidence Zero byte
if (ISimvol=0) and (PSimvol=0) then
begin
//ProgressBar. Position: = AddressFiles;
end;
end;
finally
UnmapViewOfFile (OriginalBuf);
UnmapViewOfFile (PerevedenBuf);
end;
finally
CloseHandle (OriginalMap);
CloseHandle (PerevedenMap);
end;
finally
CloseHandle (MOriginal);
CloseHandle (MPereveden);
end;
finally
FOriginal. Free;
FPereveden. Free;
EndTime: = Now;//we Fix STOP time
DelayTime: = SecondSpan (EndTime, StartTime);//we Calculate PROCEDURE runtime
MainMemo. Lines. Add (' Test run of files in a mode "TBytes" is completed! ' + #13#10 +
' test Time = ' + FloatToStr (DelayTime) + ' sec ');
end;
end;

[/spoiler] Runtime all the same Test cycle: 0,724 seconds!
So MMF did not show worthy results unfortunately!
But I a little got the hand!...:-D:-Q

94

Re: Optimization of byte reading and comparing of two binary files

makhaon wrote:

Mmf will not be faster. 10 Mb it in the modern conditions are a little even on telephono-tablets. With a view of convenience and simplicity, it is better reading in TBytes and it will be restricted. Look the remaining.

If it is the answer to my message I about it and wrote, m. Not absolutely distinctly)) that if it is possible to load in storage (for example if files some tens MB) easier and (probably) faster and to make - to load in storage.

95

Re: Optimization of byte reading and comparing of two binary files

The time runs and it is soon necessary to get into the car already...
I will return  to one place in real Procedure:

SStroka: = SStroka + AnsiChar (ISimvol);

In string variable SStroka there is thus "accumulation" of the data necessary to me.
Concatenation here is useful to me for two reasons:
1 . It is not necessary to track the pointer.
2 . The line - is the Array and besides - "dimensionless"!
The Second reason - perhaps the most important ! - There is no necessity to declare the size in advance!
P.S. I Think my experiments will be useful not only me as experience obtaining, but also to other beginners who finds this subject later!?
Everything, many thanks! - including for "the silence" which has allowed most to all ""!... smile))

96

Re: Optimization of byte reading and comparing of two binary files

Bellic wrote:

... Runtime all the same Test cycle: 0,724 seconds!
So MMF did not show worthy results unfortunately!

The basic difference between MMF and a variant on the basis of TBytes next lines:

//It is readable Both files in TBytes
FOriginal. ReadBuffer (BOriginal, SizeOriginal);
FPereveden. ReadBuffer (BPereveden, SizePereveden);

Handling of cycle TBytes is produced only in storages, and a cycle in MMF -  disk reading.  is engaged Windows. So comparing not absolutely correct.

Bellic wrote:

I Will return  to one place in real Procedure:

SStroka: = SStroka + AnsiChar (ISimvol);

In string variable SStroka there is thus "accumulation" of the data necessary to me.

At great volume  and a frequent call there is a probability of a fragmentation of storage. For fragmentation reduction it is possible to use an array by analogy with TList.

97

Re: Optimization of byte reading and comparing of two binary files

Freedoom, here there was a comparing of time for usage in real procedure, instead of is pure  theories!

98

Re: Optimization of byte reading and comparing of two binary files

Bellic, byte disk reading will be much more slowly, than reading by the unit of all file. It is the obvious fact, in my opinion, not demanding such variants of check.

99

Re: Optimization of byte reading and comparing of two binary files

wrote:

Bellic;
Try still bit-by-bit reading.

it is improbably witty!.)))

100

Re: Optimization of byte reading and comparing of two binary files

Bellic wrote:

it is passed...
Improbably witty!.)))

If to organize  with shout "let's offer even more high-speed method of comparing  while I accept food/depart to I snu/have sex (necessary to underline)", sentences will be still . It to that in all it is desirable to observe a measure