Bonjour à tous,

Je sais qu'il existe pas mal de post à propos de ce sujet mais la petite différence (et c'est là que ça pose problème)
c'est que je dois éclater mon gros fichier (~800 à 900Mo) suivant une chaîne de caractère. Je n'ai pas trouver ça.

Pour info, mon gros fichier est un fichier que je reçois qui est en fait la concaténation de fichiers XML, donc avec
à chaque fois des balises de début de fichier XML et de fin.

J'ai ma propre routine qui fonctionne très bien mais qui est affreusement lente ci-dessous:

Le code ci-dessous correspond à mon process principal, je fais des fichiers de 1000 notices XML,
j'utilise ma fonction scanBig pour rechercher les notices dans mon gros fichiers. Elle fonctionne très bien
et est assez rapide sur des petites chaînes de caractère.

Je suis ***obligé*** de passer par un prog delphi car c'est inclus dans un autre projet, je n'ai pas la possibilité
de passer par un programme intermédiaire, etc....

Pour vous donner un ordre d'idée, sur un fichier test de 450Mo, sur mon i7, rien que pour créer la première tranche de 1000 notices
cela prend au moins 5 à 6 minutes.....et il y a env. 10 000 notices dans ce test.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
        c       := PChar(Page);
        k       := 1;
        foo     := '';
        notice  := '';
 
        Pb1.Position  := 0;
        Pb1.min       := 0;
        Pb1.Max       := length(Page);
 
        Taille        := 0;
 
        while scanbig('<patent-application-publication>', '</patent-application-publication>', c, notice) do
        begin
          foo     := foo + '<patent-application-publication>' + notice + '</patent-application-publication>' + #13#10;
          Taille  := Taille + length(notice);
 
          if ((k mod 1000)=0) then
          begin
            FD:=TFileStream.Create(ExtractFilePath(Application.ExeName)+cPathInput+'\'+cPathXml+'\'+MyCurrentDir+'\'+inttostr(k)+'.xml', fmCreate);
            Try
              FD.Write(PChar(foo)^, Length(foo));
            Finally
              FD.Free;
            End;
            foo := '';
          end;
          inc(k);
 
          Pb1.position  := Taille;
        end;
 
        // On sauvegarde le reste
        FD:=TFileStream.Create(ExtractFilePath(Application.ExeName)+cPathInput+'\'+cPathXml+'\'+MyCurrentDir+'\'+inttostr(k)+'.xml', fmCreate);
        Try
          FD.Write(PChar(foo)^, Length(foo));
        Finally
          FD.Free;
        End;
        foo := '';
      End;
Ma fonction bigScan maintenant:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function ScanBig(const Search1, Search2: string; var Ch: PChar; var Text: string): Boolean;
var
  Ch1, Ch2: PChar;
begin
  Result:=False;
  if not Assigned(Ch) then
    Exit;
  Ch1 := StrPos(Ch, PChar(Search1));
  if Ch1 <> nil then
  begin
    Ch := Ch1 + Length(Search1);
    Ch2 := StrPos(Ch, PChar(Search2));
    if Ch2 <> nil then
    begin
      SetString(Text, Ch, Ch2 - Ch);
      Ch := Ch2 + Length(Search2);
    end
    else
    begin
      Text := StrPas(Ch);
      Ch := nil;
    end;
    Result := True;
  end;
end; {* func ScanBig *}

Merci pour vos conseils !!!!