[Ajuda] String com parte de outra O.o
#8

Quote:

A lot of people tend to copy strings like this:

PHP код:
format(destsizeof (dest), "%s"src); 
This is one of the worst ways to do it! I did timings on six different methods of copying strings, in all cases "b" is the destination and "a" is the source. "strcpy" is a hand written PAWN function to copy strings:

PHP код:
strmid(ba0strlen(a), sizeof (b));
format(bsizeof (b), "%s"a);
b[0] = '\0';
strcat(basizeof (b));
memcpy(ba0strlen(a) * 4sizeof (b)); // Length in bytes, not cells.
strcpy(ba);
a
Note that "b = a;" is the standard PAWN array copy and only works for arrays known at compile time to be the same size, or with a larger desination. Unfortunately I ran a range of tests and they do not point to a single best function. What they DO do is show quite clearly that both the hand coded PAWN version and format are very slow at copying strings:

For short strings in small arrays, "b = a;" is fastest when applicable, strcat with prior NULL termination (important) is second.

For short strings in large arrays, strcat is fastest.

For longer strings in longer arrays, "b = a;" is again fastest, with memcpy second.

For huge arrays "b = a;" seems to be fastest.

Where possible use standard array assignment, however this is not always possible, for example when a string of unknown size is passed to a function. In these cases I would suggest using strcat (if you're interested, note the bizzare syntax):

PHP код:
#define strcpy(%0,%1,%2) \
    
strcat((%0[0] = '\0', %0), %1, %2
Use:

PHP код:
strcpy(destsrcsizeof (dest)); 
Nгo hб necessidade em usar format, ou mesmo atualizar includes LOL
Reply


Messages In This Thread
String com parte de outra O.o - by Dayvison_ - 16.09.2015, 23:13
Re: String com parte de outra O.o - by Nixtren - 17.09.2015, 11:41
Re: String com parte de outra O.o - by [BOPE]Seu._.Madruga - 17.09.2015, 13:31
Re: String com parte de outra O.o - by PT - 17.09.2015, 14:29
Re: String com parte de outra O.o - by Dayvison_ - 17.09.2015, 14:42
Re: String com parte de outra O.o - by [BOPE]Seu._.Madruga - 17.09.2015, 14:54
Re: String com parte de outra O.o - by PT - 17.09.2015, 14:57
Re: String com parte de outra O.o - by Dayvison_ - 17.09.2015, 15:14
Re: String com parte de outra O.o - by PT - 17.09.2015, 15:26
Re: String com parte de outra O.o - by Dayvison_ - 17.09.2015, 15:28

Forum Jump:


Users browsing this thread: 2 Guest(s)