Ver Mensaje Individual
  #2  
Antiguo 12-04-2006
Avatar de halcon_rojo
halcon_rojo halcon_rojo is offline
Miembro
 
Registrado: abr 2006
Posts: 14
Reputación: 0
halcon_rojo Va por buen camino
Cool para quien le entienda

>Hello,
>>Someone knows the exact limits of TStringList.LoadFromFile ?
>>- file size ?
>- max lines ?
>- ctrl_Z in file ?
>>(I know it stops on nulls).

I don't think there should be specific filesize or maxline limits other
than those that are imposed by the
process. LoadFromFile calls LoadFromStream which calls Read which calls
HandleStream.Read which
calls FileRead which returns a pointer to a buffer and a count of the bytes
read ( a DWORD so there is a 2gb or is it 4gb limit there).

the Tstrings.LoadFromStream
looks like
Size := Stream.Size - Stream.Position;
SetString(S, nil, Size);
Stream.Read(Pointer(S)^, Size);
SetTextStr(S);
so it is clear that there is a 1 hit read of all the data on that file
until the end of file (which might not be what
you want if you have other stuff on the file). Anyway, all the data goes
into an ansistring S (which is local and will be deallocated on exit) but
afaik the memory for the underlying buffer is never freed until the
handle is finally freed .. this seems wasteful (as in, as soon as we have
finished the load we could release
the file buffer .. but I may have misread the code).

Next we have SetTextStr which is a loop that looks like so

P := Pointer(Value);
if P <> nil then
while P^ <> #0 do
begin
Start := P;
while not (P^ in [#0, #10, #13]) do Inc(P);
SetString(S, Start, P - Start);
Add(S);
if P^ = #13 then Inc(P);
if P^ = #10 then Inc(P);
end;

(I am sure Borland will forgive me for publishing this code snippet, in the
interests of science).

So, there are some possibilities of some oddities here particularly wrt
#0,#10,#13.
The #10 and #13 were put there by GetTextStr .. but you might have had
them embedded in
your original source strings. The #0 .. again, you may have had a reason
for having one or more
consecutive empty strings in your original list.

Note also the call to Add .. depending upon your settings of Sorted and, if
sorted, Duplicates this can end up
with another call to the bsearch find and Insert (even if you KNOW you are
restoring a sorted list), and some locale dependencies.


My point is that TstringList.SaveToFile and LoadFromFile are not the simple
mirror image dump and
restore of blocks of characters that one might expect. There is quite a
lot of looping and comparison and memory management going on under the
hood, so if your strings have unusual content or you need to do a lot of
this ,you might be better off considering alternative structures.

fwiw
Responder Con Cita