Page 1 of 1

StringField()

Posted: Wed Aug 08, 2007 6:33 pm
by ktamp
StringField() is not optimized for speed. PureBasic needs a fast pointer-to-pointer based function to extract fields from string, e.g. StringToken(@*PointerToString, Delimeter.s).

Another thing: Implementing my own version of such a function, I noticed that PureBasic lacks a Pointer structure:

Code: Select all

Structure Pointer
    *p
EndStructure
This structure could make library code more portable in the future (between 32 and 64bit versions), as no casting to long would be necessary.

Re: StringField()

Posted: Wed Aug 08, 2007 6:55 pm
by ts-soft
ktamp wrote: Another thing: Implementing my own version of such a function, I noticed that PureBasic lacks a Pointer structure:

Code: Select all

Structure Pointer
    *p
EndStructure
This structure could make library code more portable in the future (between 32 and 64bit versions), as no casting to long would be necessary.
You can simple define as pointer, the pointer have no type

Code: Select all

Define *mypointer
Only if you give him a structure

Posted: Wed Aug 08, 2007 7:20 pm
by Trond
StringField() is not optimized for speed.
Rest assured that PB's StringField() can't get much faster.
PureBasic needs a fast pointer-to-pointer based function to extract fields from string, e.g. StringToken(@*PointerToString, Delimeter.s).
StringField() already works like that behind the scenes.

Posted: Thu Aug 09, 2007 4:32 pm
by the.weavster
REALbasic has Split() and Join() which convert delimited strings to and from an array.

If you have a very long delimited string this works much faster than PureBasics StringField() and REALbasic usually get's a kicking in speed comparisons with PB.

I'd like to see Split() and Join() implemented in PB.

Posted: Fri Aug 10, 2007 7:27 pm
by ktamp
Trond wrote:StringField() already works like that behind the scenes.
If that was true, my StringToken() would not be lightning faster than StringField() for parsing text files stored in a string buffer. What is killing StringField() is that it needs/uses that index argument...

Posted: Fri Aug 10, 2007 7:32 pm
by ts-soft
Stringfield searches allways up the begin, thats slows it down

Posted: Fri Aug 10, 2007 7:41 pm
by Trond
ktamp wrote:
Trond wrote:StringField() already works like that behind the scenes.
If that was true, my StringToken() would not be lightning faster than StringField() for parsing text files stored in a string buffer. What is killing StringField() is that it needs/uses that index argument...
Yes, the slowdown comes from the index. What you suggested that I said that PB already does is to pass a pointer to the string instead of copying in the string.

Posted: Tue Aug 14, 2007 10:31 am
by ktamp
To Trond:
I said "pointer-to-pointer of string", like what CopyMemoryString() does.

To the.weavster:
Coming to PB from Python, at first I found myself uncomfortable with the lack of functions like Split() and Join(). Now that I have adjasted to the ways of PB, I can say I produce better code without Split() and Join(). Anyway, I have written efficient StringToList() and ListToString() procedures. If you want them to appear someware e.g. in "Tricks 'n' Tips" or be sent to you by PM, tell me.

Posted: Tue Aug 14, 2007 7:10 pm
by Flype
the.weavster wrote:REALbasic has Split() and Join() which convert delimited strings to and from an array.

If you have a very long delimited string this works much faster than PureBasics StringField() and REALbasic usually get's a kicking in speed comparisons with PB.

I'd like to see Split() and Join() implemented in PB.
you can have a look here if you want :
http://www.purebasic.fr/english/viewtopic.php?t=21495

Posted: Tue Aug 14, 2007 7:14 pm
by technicorn
You can also have a look here for a fast version:
http://www.purebasic.fr/english/viewtopic.php?t=28388

Posted: Wed Aug 15, 2007 6:27 am
by hallodri
strtok is 3 times faster as StringField

Code: Select all

	ImportC "msvcrt.lib"
	CompilerIf #PB_Compiler_Unicode
		strtok(*string,*seps) As "_wcstok"
	CompilerElse
		strtok(*string,*seps) As "_strtok"
	CompilerEndIf
	EndImport 
	 
	string.s  = "StringField() is not optimized for speed."
	string    + " PureBasic needs a fast pointer-to-pointer based function to extract fields from string, e.g. StringToken(@*PointerToString,Delimeter.s)." 
	
	Seps.s = " .(),@"
	Token  = strtok(@string,@Seps) 
    
	While Token  	
		Debug PeekS(Token)	  
		Token = strtok(#Null,@Seps)
	Wend 

Posted: Fri Aug 17, 2007 4:49 pm
by Trond
ktamp wrote:To Trond:
I said "pointer-to-pointer of string", like what CopyMemoryString() does.
And I said that it works by passing the string like CopyMemoryString() does, which is a pointer to the string.