PureBasic 6.40 alpha 1 is ready, surprise inside !
-
threedslider
- Enthusiast

- Posts: 562
- Joined: Sat Feb 12, 2022 7:15 pm
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
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.
- DeanH
- Enthusiast

- Posts: 285
- Joined: Wed May 07, 2008 4:57 am
- Location: Adelaide, South Australia
- Contact:
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
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?
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
Wow! that sounds awesome Fred, so instead of reading a string for null termination - the length is already cached?
ProGUI - Professional Graphical User Interface Library - http://www.progui.co.uk
-
Little John
- Addict

- Posts: 4837
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
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.
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
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?
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
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?
I support an application that provides independent string functions, written primarily to do this, although with performance objectives in mind also, so I'm keen to experiment further when I have chance and see if we can begin to take advantage of this change.
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
Theorically, you can put 0 in it. But it won't be officially supported for now (could evolve later but will be per command decision)
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
Fred - did you consider making another string type?
Ex. Cstring for api, FastString for internal?
Or is the plan to have new string support all api calls with null terminated strings?
Ex. Cstring for api, FastString for internal?
Or is the plan to have new string support all api calls with null terminated strings?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
There is no plan to have an additional string for API call, as they are always null terminated. The only case when it needs an adjustment is when you use a string for output buffer using Space().
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
A probably easier method to recalc the length of the string, without any fancy additional procedures:
Edit
oh god, my bad, Fred even mentioned that in the initial post
Code: Select all
PureBasicPath$ = Space(#MAX_PATH)
GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH)
Debug Len(PureBasicPath$)
PureBasicPath$ = PeekS(@PureBasicPath$)
Debug Len(PureBasicPath$)oh god, my bad, Fred even mentioned that in the initial post
Using Win32 API with Space() for example will require an extra PeekS().
{Home}.:|:.{Dialog Design0R}.:|:.{Codes}.:|:.{History Viewer Online}.:|:.{Send a Beer}
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
Or by using fryquez ResetStringLength procedure/macro: viewtopic.php?p=650721#p650721
;PeekS Len(61): 517 ms
;ResetStringLength Len(61): 350 ms
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)
CompilerEndIf;ResetStringLength Len(61): 350 ms
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
Just 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
quidquid Latine dictum sit altum videtur
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
The test on NIL (null pointer) is missing
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: PureBasic 6.40 alpha 1 is ready, surprise inside !
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.
Kinda afraid to install the patch, as I am doing a lot of String Operations, and seeing anything break that worked before in my 65k lines-project, would just cause unneccessary stress to me, lol, thanks.
- What does "patching a string by putting a zero in it" even mean?
- What are concat functions?
- An snippet of a thing that worked before, and after the patch has to be done with PeekS (never used that one either) would be great.
Now these points of data make a beautiful line,
And we're out of Beta, we're releasing on time.
And we're out of Beta, we're releasing on time.




