• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

When leaking occures? (strings)

Status
Not open for further replies.
Level 3
Joined
Oct 21, 2008
Messages
18
When do strings leak?

Is leaking when im setting variable to another variables?

like:
V1: Hi ...
V2: ... i like lemon...
V3: ... juice!
V1+V2+V3 = V4 (Hi i like lemon...)
is it leaking?

Im asking cause I have seen pretty cool system when damage done was shown in Multiboard. Looks like this......You were hit by Dragon for 235 dmg.
It seems to be pretty much of leaking if it would be game for 10 players with more action story (more fighting)

So.. is adding variables and showing them on mutliboard leaking?


- By the way, is normal chat in the game leaking?
 
Level 3
Joined
Dec 14, 2008
Messages
35
When do strings leak?

Is leaking when im setting variable to another variables?

like:
V1: Hi ...
V2: ... i like lemon...
V3: ... juice!
V1+V2+V3 = V4 (Hi i like lemon...)
is it leaking?

Im asking cause I have seen pretty cool system when damage done was shown in Multiboard. Looks like this......You were hit by Dragon for 235 dmg.
It seems to be pretty much of leaking if it would be game for 10 players with more action story (more fighting)

So.. is adding variables and showing them on mutliboard leaking?


- By the way, is normal chat in the game leaking?

Hmmm i dont know much on the topic (of Jass im a beginer =)) but i believe this probly would leak becuase, if you wanted to reset the string for like when you get hit by another monster it would need to display something else. but im not certain there may be another way to go about it, becuase otherwise the string would keep all that information and just keep adding it on top of eachother and make a big mess and waist of storage. it would really slow the game down if not done correctly.
 
Last edited:
Level 7
Joined
Jul 20, 2008
Messages
377
Strings leak in an odd way; the game recycles strings but if you're generating a new (different!) string like every .01 second, then yeah that can get bad.

However, I wouldn't worry about it too much because strings don't take up that much memory anyway.
 
Strings leak in an odd way; the game recycles strings but if you're generating a new (different!) string like every .01 second, then yeah that can get bad.
Just to make your point clearer, the game has a table of strings which is added to every time you create (or use) a string which has never been created or used before. This will only cause problems if nearly all of the strings you create are different, and you create a lot (the definition of "a lot" depends on how long the strings are, for example an integer converted to a string would barely leak at all).

However, I wouldn't worry about it too much because strings don't take up that much memory anyway.
As I already said, they can take up a lot of memory if they are very long.
 
Level 3
Joined
Oct 21, 2008
Messages
18
soooo, the best how to do such system (as i mentioned in the first post), would be creating multiboard with more comlumns, and in each column place string (eg. name of attacker) and to the other one, the integer (dmg),
that meana that no new strings would be created


.........right?

And what about substrings, is substring a new string?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
As I already said, they can take up a lot of memory if they are very long.
512 bytes to be exact, if WC3 uses 16 bit unicode for the largest string. If it uses 32 bits per character (for some stupid reason) that is a max of 1 KB. Honestly, unless you are generating hidious ammounts of unique 256 character string, it is not a problem as most PCs atleast have a GB free nowdays when running WC3.
 
Level 6
Joined
Mar 20, 2008
Messages
208
The best way to do this would be to use a set of global strings and just keep them updated.
Two things could occur.
1. The string will be overwritten, byte for byte - slower
2. The string pointer will simply point to the new string in memory. - faster

If its #2, you have old strings floating around in memory limbo, but I think blizzard has a garbage collector, either that or it gets overwritten because chat does not lag regular games.
 
Level 6
Joined
Mar 20, 2008
Messages
208
It's number 1, strings aren't pointers. But each new string is added to a table of used strings, to make things faster if that string is used again. These are never deleted until the game ends.

So then the question is, will a change to a global string change the string in that table, or does the table add an entire new string to it?

If it adds them to the table, he's pretty much screwed then?
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
It's number 1, strings aren't pointers. But each new string is added to a table of used strings, to make things faster if that string is used again. These are never deleted until the game ends.
No, in that case it's neither number 1 nor number 2.

Technically, since there's a string table, the most plausible scenario is a table of pointers to strings.

That's why option 2 sounds the most realistic.

Also note how using the returnbug on strings returns a very small unique integer, which I interpret as the table index of the string. Which to me means that what's behind that index must be a pointer, and not a direct array of characters.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
Well, the pointers for WC3 for the same string are constant within that instance of the map. Like I said, they use hash tables for speed which tend to store stuff statically. The actual strings are purly array of characters referenced from the table via a location and size value.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Actually, the pointer stored by the variable probably points to a hash table which then points to the actual string. This is to allow quick comparisions of strings and also allows an efficent way to avoid duplicate strings.

That's what I said?

Yeah, but that still doesn't answer my question - how can you have constant pointers?
The "constant" qualifier only has a meaning in the high-level programming concept. There's no such thing as "constant" when it comes down to binaries, so "how you can have constant pointers" doesn't make a lot of sense. How can you have constant integers, for that matter?

And you usually can't perform direct operations (such as concatenation) on pointers either.
huh? Don't know what you're saying now...

This is how I think it works. Note that it's mainly speculative, because I don't think anyone without the source code can truly know it:

String: a pointer to a "character".
==> When printing a string, it keeps incrementing the pointer with 1 (1 byte) until it reaches "null" (again speculative, but it's most common to use zero terminated strings)
==> When using operators on the string, such as concatenate or substring, a new string is generated, which means new memory is allocated containing the characters from both strings, concatenated. The string object is accessed by a pointer.

Whenever a new string is constructed (by assignment or concatenation operators), a pointer to the string is added to a hashtable for fast retrieval and comparison.

The string variable in jass is neither a pointer nor an array of characters (in the end, there's no difference anyway), but actually the index to the hashtable. When string 1 with index 1 to the table is concatenated with string 2 (index 2) and apparently becomes equal to string 3 with index 3, the string 1 variable will now become index 3.
 
Status
Not open for further replies.
Top