Speed of loading a file to editorgadget

Just starting out? Need help? Post your questions and find answers here.
Grumble
User
User
Posts: 31
Joined: Sun Jun 15, 2003 8:44 pm

Speed of loading a file to editorgadget

Post 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....
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post 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
Tranquil
Grumble
User
User
Posts: 31
Joined: Sun Jun 15, 2003 8:44 pm

Post 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.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

What size are the files you're using to test?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Grumble
User
User
Posts: 31
Joined: Sun Jun 15, 2003 8:44 pm

Post 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 ?
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Hi

Look at this link : viewtopic.php?t=6679

and say thank u to El_Choni 8)

Best Regards
Henrik.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Speed of loading a file to editorgadget

Post 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.
ARGENTINA WORLD CHAMPION
Grumble
User
User
Posts: 31
Joined: Sun Jun 15, 2003 8:44 pm

Post 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 !!
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Grumble wrote: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 !!
:?: :?: :?: :?: :?:

I have used (without the SetGadgetText part) a lot of times to load a file on memory and never crashed!

I don't know the memory limit of the EditorGadget, but the problem must be there, test just loading the file on memory and you will see that don't crash never (with the 64k limit), but you could use memorybank instead of the String.
ARGENTINA WORLD CHAMPION
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post 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)
El_Choni
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post 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 ?
SPAMINATOR NR.1
Grumble
User
User
Posts: 31
Joined: Sun Jun 15, 2003 8:44 pm

Post 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 !
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post 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 :wink:

Best Regards
Henrik.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post 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 :wink:

Best Regards
Henrik.
i tested it successfully with a 18MB Textfile :)
SPAMINATOR NR.1
Post Reply