Whats the size limitation for the StringGadget gadget?

Just starting out? Need help? Post your questions and find answers here.
upnorth
User
User
Posts: 18
Joined: Wed Jul 21, 2004 8:54 pm
Location: California, USA

Post by upnorth »

All this stuff is a lot of work to load a 115k text file into an editor gadget IMHO.

This code will do it in a few seconds if that's fast enough for you.

As for the original question, StringGadgets are better suited for smaller amounts of text, say 32k or maybe even 64k on systems with a lot of RAM. The memory management of those gadgets is treated differently acccording to Microsoft and they should not be used for large amounts of data. EditorGadgets should be used for larger texts. In many cases you will have to set their maximum size limits as described in the posts above.

Hope this helps.

Code: Select all

Enumeration 
  #Window_0 
  #Editor_0 
EndEnumeration 

Procedure GetText(File.s)
  MyFile.l = ReadFile(#PB_Any, File)
  a.l = 0 
  Repeat
     MyData.s = ReadString() 
     AddGadgetItem(#Editor_0,a,MyData)
     a + 1
  Until Eof(MyFile) 
  CloseFile(MyFile) 
EndProcedure 

  FileName.s = "C:\temp\115k.txt" ; <---Your File Name Here
  If OpenWindow(#Window_0,10,10,640,480,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"EditorGadget") And CreateGadgetList(WindowID(0)) 
    EditorGadget (#Editor_0,10,10,620,460,#PB_Container_Raised)
    MyTime.l = GetTickCount_() 
    GetText(FileName)
    MyTime = GetTickCount_() - MyTime
    MessageRequester("Done.", "File Loaded in " + Str(MyTime / 1000) + " Seconds.") 
    Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow 
  EndIf 
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

upnorth,

I made a benchmark using an editor gadget, with my reference 'big text file' which makes exactly 4 670 689 bytes.

My computer is a 1,2GHz, 256MB ram running WIN2K.

The download time is about 1300 ms (GetText() time).

Rgrds
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

c++ has a nice iostream library... 8O
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

upnorth, that took exactly 1 second on my machine.
AMD Athlon 2 Ghz Thoroughbred with 512 MB RAM.

Thanks alot, I think I'll go for this solution :) :D
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
upnorth
User
User
Posts: 18
Joined: Wed Jul 21, 2004 8:54 pm
Location: California, USA

Post by upnorth »

Hey fweil & GeoTrail - My first example was meant to show that it could be done with native PB commands and without reallocating the PB String manipulation space. It would get pretty slow loading one line at a time if the text file gets much larger.

If speed is the most important factor, try this API example. 5214088 bytes loaded in 1016 Milliseconds on my PIII 450.

And hey fsw, thanks but no thanks, no C++ for me.

Careful, there's no error checking in this code. Have Fun! :D

Code: Select all

Enumeration 
  #Window_0 
  #Editor_0 
EndEnumeration 

#MaxFileSize = 8388608 ; 8 Megs

Procedure.l GetText(File.s)
  *MemoryID = AllocateMemory(#MaxFileSize)
  Fhandle=CreateFile_(@File,#GENERIC_READ,#FILE_SHARE_READ,#NULL,#OPEN_EXISTING,#FILE_ATTRIBUTE_NORMAL,#NULL ) 
  Count.l=0 
  Result.l = ReadFile_(FHandle,*MemoryID,#MaxFileSize,@Count,0) 
  Result = SendMessage_(GadgetID(#Editor_0),#WM_SETTEXT,#NULL,*MemoryID)  
  FreeMemory(*MemoryID) 
  CloseHandle_(Fhandle) 
  ProcedureReturn Count
EndProcedure 

FileName.s = "C:\temp\bible.txt" 
If OpenWindow(#Window_0,10,10,640,480,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"EditorGadget") And CreateGadgetList(WindowID(0)) 
  EditorGadget (#Editor_0,10,10,620,460,#PB_Container_Raised)
  MyTime.l = GetTickCount_() 
  BytesLoaded.l = GetText(FileName)
  MyTime = GetTickCount_() - MyTime
  MessageRequester("Done.", Str(BytesLoaded) + " Bytes Loaded in " + Str(MyTime) + " MilliSeconds.") 
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow 
EndIf 
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

upnorth, that looks very interesting. I can't test it right now since I'm on a Linux machine and can't figure out how to install PB on this thing :lol:

Anyways, I'll check it out as soon as possible.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Post Reply