Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
Posted: Mon Jan 26, 2026 3:13 pm
Thanks Fred.
http://www.purebasic.com
https://www.purebasic.fr/english/
BarryG wrote: Mon Jan 26, 2026 12:50 pmLet's compare that with PureBasic 5.73:User_Russian wrote: Mon Jan 26, 2026 11:28 amMessageRequester() - 267 KB.
Empty source file - 265 KB.
MessageRequester() - 4.50 KB.
Empty source file - 2 KB.
That's why I still use 5.73 for my private projects.The old PureBasics were so lean and clean.
Yes, that is the case:PrincieD wrote: Tue Jan 27, 2026 7:14 am Wow! that sounds awesome Fred, so instead of reading a string for null termination - the length is already cached?
It's the way e.g. Turbo Basic did it already about 35 years ago.Fred wrote:All strings are now prefixed by their length (except the strings in DataSection). [...]
That means than all string operation will have instant length information resulting in faster operation as iterating byte by byte on the string to find the null terminated char is no more needed.
It's an integer minus 1 bit (31 bit on x86, 63 bit on x64).DeanH wrote: Tue Jan 27, 2026 5:11 am The change to string handling sounds similar to the old BSTR string type. Much faster to read records from a large SQLite database. Question: how is the length stored? Long? Quad? Another way? Does it limit the maximum length of a string?
I appreciate you said in the opening post that the terminating null is still retained, but could this possibly lead eventually to an ability to store x'00 in string values?Fred wrote: Tue Jan 27, 2026 11:39 amIt's an integer minus 1 bit (31 bit on x86, 63 bit on x64).DeanH wrote: Tue Jan 27, 2026 5:11 am The change to string handling sounds similar to the old BSTR string type. Much faster to read records from a large SQLite database. Question: how is the length stored? Long? Quad? Another way? Does it limit the maximum length of a string?
Code: Select all
PureBasicPath$ = Space(#MAX_PATH)
GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH)
Debug Len(PureBasicPath$)
PureBasicPath$ = PeekS(@PureBasicPath$)
Debug Len(PureBasicPath$)Using Win32 API with Space() for example will require an extra PeekS().
Code: Select all
CompilerIf #PB_Compiler_Version >= 640
Declare ResetStringLength(*s.Character)
Procedure ResetStringLength(*s.Character)
Protected *p.Integer = *s -SizeOf(Integer)
*p\i = 0
While *s\c
*p\i + 1
*s + SizeOf(Character)
Wend
EndProcedure
CompilerElse
Macro ResetStringLength(s)
;
EndMacro
CompilerEndIf
CompilerIf Not #PB_Compiler_Debugger
OpenConsole("ResetStringLength")
Start = ElapsedMilliseconds()
For l = 0 To 5000000
PureBasicPath$ = Space(#MAX_PATH)
GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH)
PureBasicPath$ = PeekS(@PureBasicPath$)
Next
PrintN("PeekS Len(" + Str(Len(PureBasicPath$)) + "): " + Str(ElapsedMilliseconds() - Start) + " ms")
Start = ElapsedMilliseconds()
For l = 0 To 5000000
PureBasicPath$ = Space(#MAX_PATH)
GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH)
ResetStringLength(@PureBasicPath$)
Next
PrintN("ResetStringLength Len(" + Str(Len(PureBasicPath$)) + "): " + Str(ElapsedMilliseconds() - Start) + " ms")
Delay(10000)
CompilerEndIfJust don't act surprised when that code breaks in the future because you are clearly messing with internals here. There is such a thing as over-optimizing.ChrisR wrote: Tue Jan 27, 2026 7:44 pm Or by using fryquez ResetStringLength procedure/macro: viewtopic.php?p=650721#p650721
;PeekS Len(61): 517 msCode: Select all
CompilerIf #PB_Compiler_Version >= 640 Declare ResetStringLength(*s.Character) Procedure ResetStringLength(*s.Character) Protected *p.Integer = *s -SizeOf(Integer) *p\i = 0 While *s\c *p\i + 1 *s + SizeOf(Character) Wend EndProcedure CompilerElse Macro ResetStringLength(s) ; EndMacro CompilerEndIf CompilerIf Not #PB_Compiler_Debugger OpenConsole("ResetStringLength") Start = ElapsedMilliseconds() For l = 0 To 5000000 PureBasicPath$ = Space(#MAX_PATH) GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH) PureBasicPath$ = PeekS(@PureBasicPath$) Next PrintN("PeekS Len(" + Str(Len(PureBasicPath$)) + "): " + Str(ElapsedMilliseconds() - Start) + " ms") Start = ElapsedMilliseconds() For l = 0 To 5000000 PureBasicPath$ = Space(#MAX_PATH) GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH) ResetStringLength(@PureBasicPath$) Next PrintN("ResetStringLength Len(" + Str(Len(PureBasicPath$)) + "): " + Str(ElapsedMilliseconds() - Start) + " ms") Delay(10000) CompilerEndIf
;ResetStringLength Len(61): 350 ms
Please, for really stupid people like me, can you explain in layman's terms what that actually means?Fred wrote: Fri Jan 23, 2026 10:47 amBasically if you patch a string by putting a zero in it, the Len() function will be wrong, and the concat functions will fail. You will need to use PeekS() for this.