Page 1 of 1
Speed of loading a file to editorgadget
Posted: Tue Jun 24, 2003 8:10 pm
by Grumble
Hi,
I'm trying to load a textfile into an editorgadget, with several variations on this code:
Code: Select all
If ReadFile(1, File$)
While Eof(1)=0
Text$ = Text$+ReadString()+Chr(13)+ Chr(10)
Wend
CloseFile(1)
SetGadgetText(#MyEditorGadget, Text$)
EndIf
Except for very small files this works extremely slow, and for a textfile of about 500 kB the program seems to crash. Since Purebasic is known for speed I must be doing something wrong....
Posted: Tue Jun 24, 2003 8:21 pm
by Tranquil
Unfortunately PB supports only strings up to 64kByte. Longer strings can not be hold atm. This is a known problem and Fred is working on this issue. But we have to wait for 4.0 as it seems.
Anyway, try using Rings FastFileLib or read the data as a binary and parse it to the string. I littlebit complicated but should work faster.
Cheers
Mike
Posted: Tue Jun 24, 2003 9:39 pm
by Grumble
Ok, I understand now that strings should be smaller than 64k, so I changed the code to add the text per line:
Code: Select all
If ReadFile(1, File$)
While Eof(1)=0
Text$= ReadString()
AddGadgetItem(#MyEditorGadget,0, Text$)
Wend
CloseFile(1)
EndIf
This solves the 64k limitation, but it's still painfully slow.
Posted: Tue Jun 24, 2003 9:49 pm
by Karbon
What size are the files you're using to test?
Posted: Tue Jun 24, 2003 10:27 pm
by Grumble
I tested with the setuplog.txt file that's in the root of the C-drive, this is a simple 110 kb textfile that loads in a flash in the PB editor, but takes about 6 seconds with my code. Perhaps I'm using the wrong gadget-type or the wrong method to enter the text into it ?
Posted: Tue Jun 24, 2003 11:14 pm
by Henrik
Hi
Look at this link :
viewtopic.php?t=6679
and say thank u to El_Choni
Best Regards
Henrik.
Re: Speed of loading a file to editorgadget
Posted: Wed Jun 25, 2003 12:11 am
by ricardo
Hi,
Why dont you read it directly into the string (or memory if its > 64k)?
Code: Select all
If OpenFile(0,"file.txt")
String$ = Space(Lof())
ReadData(@String$,Lof())
CloseFile(0)
SetGadgetText(#MyEditorGadget, String$)
EndIf
I haven't tested but should work very fast.
Posted: Wed Jun 25, 2003 8:40 pm
by Grumble
Ricardo's code crashes "PUREBASIC5913533" with several files that I've tried, but Henrik's suggestion (yes, with thanks to El Choni) works fine, although I must admit that I do not yet fully understand the code (I'm just starting with Purebasic).
Thanks !!
Posted: Wed Jun 25, 2003 10:30 pm
by ricardo
Posted: Thu Jun 26, 2003 12:54 pm
by El_Choni
"...a rich edit control will never contain more than 32K of text, unless you extend this limit by using the EM_EXLIMITTEXT message."
Code: Select all
SendMessage_(GadgetID(#EditorGadget), #EM_LIMITTEXT, -1, 0)
Posted: Thu Jun 26, 2003 2:09 pm
by Rings
try this very fast Textfile-loader for the editorgadget .(fastFile library is needed (find at the Resourcesite):)
Code: Select all
#EditorGadget=1
#ButtonGadget=2
If OpenWindow(0, 342, 196, 422, 234, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "New window ( 0 )")
If CreateGadgetList(WindowID())
EditorGadget(#EditorGadget, 10, 10, 400, 170)
ButtonGadget(#ButtonGadget, 10, 190, 110, 30, "Go and load txt file")
EndIf
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget
GadgetID = EventGadgetID()
If GadgetID = #ButtonGadget
Filename.s=OpenFileRequester("choose txt file","","*.txt|*.TXT",0)
If Filename<>""
ADR=FastOpenFile(Filename.s)
If ADR
SendMessage_(GadgetID(#EditorGadget), #EM_LIMITTEXT, -1, 0) ;Extentd the editogadget
SendMessage_(GadgetID(#EditorGadget), #WM_SETTEXT, 0, ADR) ;Place the Content
FastCloseFile()
EndIf
EndIf
EndIf
EndIf
Until Event = #PB_EventCloseWindow
EndIf
End
Is there any need for a EditorGadgetLOAD or EditorGadgetSave Command ?
Posted: Thu Jun 26, 2003 6:42 pm
by Grumble
I have used (without the SetGadgetText part) a lot of times to load a file on memory and never crashed!
Yes Ricardo, the code crashed because of the 64k limitation. with smaller files no problem like you explained.
For all who responded: thanks for all your suggestions !
Posted: Thu Jun 26, 2003 7:24 pm
by Henrik
Yes Rings this workes great , just tried with a 185k *.rtf file, And the rtf format is of course important here.
Rings wrote:
Is there any need for a EditorGadgetLOAD or EditorGadgetSave Command ?
Why not it would make life easier for newcomer's
Best Regards
Henrik.
Posted: Fri Jun 27, 2003 10:34 am
by Rings
Henrik wrote:Yes Rings this workes great , just tried with a 185k *.rtf file, And the rtf format is of course important here.
Rings wrote:
Is there any need for a EditorGadgetLOAD or EditorGadgetSave Command ?
Why not it would make life easier for newcomer's
Best Regards
Henrik.
i tested it successfully with a 18MB Textfile
