StringField()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
ktamp
User
User
Posts: 16
Joined: Sun Jul 01, 2007 4:35 pm

StringField()

Post 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.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: StringField()

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
the.weavster
Addict
Addict
Posts: 1576
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Post 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.
ktamp
User
User
Posts: 16
Joined: Sun Jul 01, 2007 4:35 pm

Post 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...
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Stringfield searches allways up the begin, thats slows it down
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
ktamp
User
User
Posts: 16
Joined: Sun Jul 01, 2007 4:35 pm

Post 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.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
technicorn
Enthusiast
Enthusiast
Posts: 105
Joined: Wed Jan 18, 2006 7:40 pm
Location: Hamburg

Post by technicorn »

You can also have a look here for a fast version:
http://www.purebasic.fr/english/viewtopic.php?t=28388
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Post 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 
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
Post Reply