PureBasic 6.40 alpha 1 is ready, surprise inside !

Developed or developing a new product in PureBasic? Tell the world about it.
akee
Enthusiast
Enthusiast
Posts: 502
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by akee »

Thanks Fred.
threedslider
Enthusiast
Enthusiast
Posts: 562
Joined: Sat Feb 12, 2022 7:15 pm

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by threedslider »

BarryG wrote: Mon Jan 26, 2026 12:50 pm
User_Russian wrote: Mon Jan 26, 2026 11:28 amMessageRequester() - 267 KB.
Empty source file - 265 KB.
Let's compare that with PureBasic 5.73:

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.
:shock:
User avatar
DeanH
Enthusiast
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 !

Post by DeanH »

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?
PrincieD
Addict
Addict
Posts: 894
Joined: Wed Aug 10, 2005 2:08 pm
Location: Yorkshire, England
Contact:

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by PrincieD »

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
Addict
Posts: 4837
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by Little John »

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?
Yes, that is the case:
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 the way e.g. Turbo Basic did it already about 35 years ago. ;-)
Fred
Administrator
Administrator
Posts: 18474
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by Fred »

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?
It's an integer minus 1 bit (31 bit on x86, 63 bit on x64).
Matheos
New User
New User
Posts: 5
Joined: Sat Dec 13, 2025 9:23 pm

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by Matheos »

Fred wrote: Tue Jan 27, 2026 11:39 am
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?
It's an integer minus 1 bit (31 bit on x86, 63 bit on x64).
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?

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.
Fred
Administrator
Administrator
Posts: 18474
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by Fred »

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)
User avatar
skywalk
Addict
Addict
Posts: 4298
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by skywalk »

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?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Fred
Administrator
Administrator
Posts: 18474
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by Fred »

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().
User avatar
HeX0R
Addict
Addict
Posts: 1242
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by HeX0R »

A probably easier method to recalc the length of the string, without any fancy additional procedures:

Code: Select all

PureBasicPath$ = Space(#MAX_PATH)
GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH)
Debug Len(PureBasicPath$)
PureBasicPath$ = PeekS(@PureBasicPath$)
Debug Len(PureBasicPath$)
Edit
oh god, my bad, Fred even mentioned that in the initial post :shock:
Using Win32 API with Space() for example will require an extra PeekS().
User avatar
ChrisR
Addict
Addict
Posts: 1562
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by ChrisR »

Or by using fryquez ResetStringLength procedure/macro: viewtopic.php?p=650721#p650721

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
;PeekS Len(61): 517 ms
;ResetStringLength Len(61): 350 ms
freak
PureBasic Team
PureBasic Team
Posts: 5956
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by freak »

ChrisR wrote: Tue Jan 27, 2026 7:44 pm Or by using fryquez ResetStringLength procedure/macro: viewtopic.php?p=650721#p650721

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
;PeekS Len(61): 517 ms
;ResetStringLength Len(61): 350 ms
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.
quidquid Latine dictum sit altum videtur
User avatar
mk-soft
Always Here
Always Here
Posts: 6515
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by mk-soft »

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
User avatar
diceman
User
User
Posts: 75
Joined: Tue Apr 10, 2018 9:42 pm

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by diceman »

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.
Please, for really stupid people like me, can you explain in layman's terms what that actually means? :o
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.
Post Reply