Packed String Support
#1

I've been looking at packed strings a lot recently trying to figure out how useful they'd be. After reading some topics here on the forums, a few people have said that most of the native SA-MP functions don't support packed strings.

I ran this:

pawn Код:
new pStr[9 char] = !"Hello World";
print(pStr);
SendClientMessageToAll(-1, pStr);
It printed the messsage in the console, and also sent the client message. My question: what functions don't support packed strings? I also tested a few (~10) other functions which took string arguments, and they worked fine also..

P.S. Not sure why, but it works when the size is only 9 chars, even though the string is 11 chars. Any lower and it produces the error 'initialization data exceeds declared size'. Can someone explain this?

The only thing I can think of that doesn't support packed strings (at least I don't think so) is format().

EDIT: Just tested format() - seems to work both ways (formatting a packed string with normal strings (and other values i.e. floats/ints) and formatting an unpacked string with a packed string in it (%s)).
Reply
#2

You can't have a part of a cell, so the calculation is rounded upwards. 9/4 = 2.25, rounded upwards to 3. Enough to hold 11 characters and a null terminator. 8/4 = 2, enough to hold 7 characters and a null terminator.
Reply
#3

Ah I understand, thanks.

Any more info on the support by functions?
Reply
#4

Quote:
Originally Posted by MP2
Посмотреть сообщение
pawn Код:
new pStr[9 char] = !"Hello World";
print(pStr);
SendClientMessageToAll(-1, pStr);
P.S. Not sure why, but it works when the size is only 9 chars, even though the string is 11 chars. Any lower and it produces the error 'initialization data exceeds declared size'. Can someone explain this?
Quote:

in most character sets a character typically takes only a single byte and a cell typicall is a four-byte entity: storing a single character per cell is then a 75% waste. For the sake of compactness, PAWN supports packed strings, where each cell holds as many characters as fit. In our example, one cell would contain four characters, and there is no space wasted.

So shouldn't even 3 cells suffice? (3* 4 == 12 characters < 11 characters of "hello world" ?
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)