What is the maximum string length

Hi. Please forgive me, cause is will be stated somewhere, but I can’t find it. What is the maximum length of a string in gpscript. This is because I like to create larger sysex messages.

Thanks

1 Like

I tested with this code and got no compilation error

var S : String

initialization
 S = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
end

Or with this syntax

var S : String

initialization
 S = <<< 1234567890123456789012345678901234567890123456789012345678901234567890
 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123
 45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
 34567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
 890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123
 456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123
 456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123
 4567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901
 2345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
 901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123
 4567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
 5678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
 89012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
 2345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
 3456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123
 45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
 3456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901
 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901
 2345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
 5678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
 89012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901
 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
 678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 >>>
end

Thank you. But I want to build it ‘in code’. So it is not about the maximum of the ide, but internally.

Pseudo code:

for x=;x<8000;x=x+1 do
S=S+”01”
End

I’ve left out the sysex header and trailer.

Not that the ide is too shabby in this respect :grinning:

What do you want to achieve with that large syses message?
Transfer Patches to Hardware?

I’ve created a jsfx plugin, that I want to send ‘patchnames’, typically this will be songpart names. The maximum patches will be 64, so I was thinking 64 names from about 64 characters long. That is 4096 characters plus 64 separators. In hex that boils down to a little over 8192 bytes.

Otherwise I’ll have to build a way to send it in parts, but that’s more complicated

How about sending OSC messages?

Read the String section of the GPScript functions documentation. You can manipulate strings as you want.

Jsfx (reaper plugin) does not support osc. Sending a sysex message is the only way to transfer a blob. I’m not having too much trouble with that. I just want to make my code solid enough. I cannot possibly imagine someone having a song with 64 parts, but I don’t want to be the limiting factor, although the ‘someone’ will most likely be myself :grin:

The manipulating is not the problem, but there might be limitations, as there are also limitations to arrays.

But when there is no official statement about the maximum length, I can create a test script, determine when it breaks and then stay well below that maximum.

Thank you all

1 Like

OK, then please report your findings here :wink:

I will. Thank you all and have a nice day.

2 Likes

@pianopaul’s example is 6200 bytes long, so that is at least possible

1 Like

I created this little script to verify the maximum length of a string. It might be more, but some of the functions for manipulating strings use apparently 32 bit signed integers, amongst the Length(s), so I cannot test further than a string length of 2,147,483,647 bytes (being (2 ^ 31) - 1)

Initialization
var s : string
    i : integer
    
    Print ("Start: " + FormatTime(ClockTime(), "%H:%M:%S"))

    s = "01234567"
    for i = 0; i < 27; i = i + 1 do
        s = s + s
    end
    s = s + CopySubstring (s, 0, Length(s) - 9) + "ABCDEGHI"

    Print ("Stop: " + FormatTime(ClockTime(), "%H:%M:%S"))
    Print (Length(s))
    Print (CopySubstring (s, Length(s) - 16, 16)) // Should be "70123456ABCDEFGHI"
End

As it turns out, the max length is exactly ‘MAXINT’ bytes (signed), so to be more precise (2 ^ 31) - 1 bytes == 2,147,483,647 bytes.

Shame on you! Not even cared for using an unsigned int :rofl: ?! (just kidding). I think this will do more than nicely.

Because the memory has to be allocated, bigger strings will be slower to assign. They are also a lot slower to use.

GPScript does not have a concept of an unsigned integer.

Very sorry if that’s not enough for you :slight_smile: That said, do not depend on that undocumented max length - the max length is deliberately not defined so that we can change it in the future if it becomes necessary.

Indeed — strings are absolutely not intended to be used for any real-time purpose.

GPScript does not have a concept of an unsigned integer

I was just joking, as you undoubtedly did understand. As far as I can see .Net has the same limit. I’m really enjoying Gigperformer. And in the domain Gigperformer and gpscript are operating, I do not see much need for longer strings either.

Keep up the good work!

I think Microsoft named .Net so it wouldn’t show up in a Unix directory listing.
— Oktal