Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Speeding up string conversion
Message
De
16/03/2005 05:59:12
 
 
À
16/03/2005 03:26:00
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00996197
Message ID:
00996222
Vues:
22
>I need to convert binary strings to ascii by changing nonprintable non-ascii
>charaters to a \\nnn strings where nnn is octal representation.
>
>I created the following routine. For 381 KB byte strings, the conversion takes 5 (!) minutes and task manager shows that my application takes a lot of MBs memory.
>
>Any way to speed up this conversion ?
>
>
FUNCTION toBYTEA( cStr )
>
>LOCAL i, j, cRes, nChr, cDig
>
>cRes = ''
>FOR i=1 TO LEN(m.cStr)
>  nChr = ASC( SUBSTR( m.cStr, m.i,1))
>  * The following four lines cna be removed if this can speed the conversion.
>  IF BETWEEN( nChr, 32,126 ) AND !INLIST( nChr,39,92)
>    cRes = m.cRes + SUBSTR( m.cStr, m.i,1)
>    LOOP
>    ENDIF
>
>  cDig = ''
>  FOR j=1 TO 3
>    cDig= CHR(ASC('0')+ m.nChr%8) + m.cDig
>    nChr = INT(m.nChr/8)
>    ENDFOR
>  cRes = m.cRes + '\\'+ m.cDig
>  ENDFOR
>RETURN m.cRes
>ENDFUNC
Andrus,

VFP's code optimization is near to zero.

With your code VFP copy the 381KB string
1+381KB*(1+x+0.5+)=381000 ..780000 times
Then VFP move more of 150..304GB !

Until a VFPM (Calvin Hsia ? ) implement a @m.string reference for VFP commands
all VFP programs with large string suffer of this problem.

This can reduce the time ( put m. everywhere )
FUNCTION toBYTEA( cStr )

	PRIVATE i,  cRes, cChr, nChr

	cRes = ''
	FOR i=1 TO LEN(m.cStr)
		STORE SUBSTR( m.cStr, m.i,1)	TO cChr
		STORE ASC( m.cChr)				TO nChr
		cRes = m.cRes + IIF(BETWEEN( m.nChr, 32,126 ) AND !INLIST( m.nChr,39,92);
	  			,	m.cChr	;
	  			,	'\\'+ CHR(48+ BITAND(m.nChr/64,7))+CHR(48+ BITAND(m.nChr/8,7))+CHR(48+ BITAND(m.nChr,7)))
	ENDFOR
	RETURN m.cRes
ENDFUNC
your Vfp VERSION ?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform