How many extra bytes are in the string?
How many extra bytes are in the string?
I have heard that when creating a string, a little more bytes are allocated than necessary, so when adding a pair of CRLF characters to a string, there is no memory overallocation (ReAllocateMemory) and it works quickly. I'm wondering how many bytes are allocated more than required. How many characters can I add to a string without causing memory overload.
Re: How many extra bytes are in the string?
Ouch, that is not guaranteed behavior.
You must assume your string byte length is accurate and not use "behind the scenes" padding.
You must assume your string byte length is accurate and not use "behind the scenes" padding.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: How many extra bytes are in the string?
This will be the standard method
Code: Select all
strind + #CRLF$ + #TAB$I want to know in which case I can use the normal method and in which case I have to use the CopyMemoryString() function.
Last edited by AZJIO on Thu May 22, 2025 9:06 pm, edited 1 time in total.
Re: How many extra bytes are in the string?
It is requested as much memory as one needs and goes coherently.
You can also forcibly release the string memory
Start without debugger as console and watch memory
You can also forcibly release the string memory
Start without debugger as console and watch memory
Code: Select all
Define i.i, s.s
mb = 1024*1024*16
If OpenConsole()
i + 1
PrintN("" + i + ": no string")
Input()
i + 1
s = Space(mb)
PrintN("" + i + ": 16mb unicode string")
Input()
i + 1
s + Space(mb)
PrintN("" + i + ": plus 16mb unicode string")
Input()
i + 1
PrintN("" + i + ": release string")
s = #Null$
Input()
EndIf
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: How many extra bytes are in the string?
I struggled with this at my early Assembler tests with Strings. At the beginning I did not understand what are the values after the end of the String.
The allocation is 4 Byte aligned at x86 and 8 Byte aligend at x64. So number of charcters * SizeOf(Charcter) + CHR(0) + FillBytesForMemoryAling
So you can write without problems until the end of the aligned size. At x64 and Charsiez=2 this are maximal 3 characters more than you String.
The allocation is 4 Byte aligned at x86 and 8 Byte aligend at x64. So number of charcters * SizeOf(Charcter) + CHR(0) + FillBytesForMemoryAling
So you can write without problems until the end of the aligned size. At x64 and Charsiez=2 this are maximal 3 characters more than you String.
Re: How many extra bytes are in the string?
PureBasic decides internally how much memory is reserved behind the string ...
Code: Select all
Define a$
For i = 1 To 100
a$ + "x"
Debug "pString = " + @a$
Next
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


