Length limits for string functions

Everything else that doesn't fall into one of the other PB categories.
User avatar
Michael Vogel
Addict
Addict
Posts: 2867
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Length limits for string functions

Post by Michael Vogel »

I just want to tell you about some observations with an older code which worked fine in a program for two or three years already...
...but today, this program crashed on a "normal" windows XP PC. I used the debugger to find, that the following code was the reason for the problem:

Code: Select all

Procedure.s StringMid(*Adresse,Start,Laenge)

	#MaxString=1<<30

	If *Adresse
		If Laenge
			ProcedureReturn PeekS(*Adresse+Start,Laenge)
		EndIf
	EndIf

	ProcedureReturn ""

EndProcedure
#MaxString has been defined to be used in certain calls like StringMid(@Temp,#SortbyDatePos,#MaxString) and never made problems on 2000, XP, Vista and even W7 PCs.

A change to #MaxString=1<<29 was all I had to do to get rid of the crashes :shock:
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Length limits for string functions

Post by Kaeru Gaman »

is it an ASCII/Unicode problem?

2^30 chars is 1GB in ASCII, 2GB in Unicode.
allocating 1GB may work, allocationg two will crash, on a 32bit system.
oh... and have a nice day.
User avatar
Michael Vogel
Addict
Addict
Posts: 2867
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Length limits for string functions

Post by Michael Vogel »

Kaeru Gaman wrote:is it an ASCII/Unicode problem?
No, the compiler option has been set to ASCII. The resulting exe file has been tested already on different PCs, therefore I was quite astonished when windows presented me the "nice" crash dialog. It was a 32 Bit-XP system, the same OS I have on my "development plattform" (a small netbook) :|

The best is to reduce the value for the constant to 1<<28, because 28 is not a prime :lol:

Michael
Post Reply