wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 07-24-2009, 07:14 PM   #1
Cheezeman
User
 
Cheezeman's Avatar
 
Join Date: Apr 2009
Posts: 179

Cheezeman has little to show at this moment (1)

Question A somewhat embarrassing question

Just like the title says, I'm kind of embarrassed to ask this question
How is it better to attach all* handles to a variable and then null them in the end, than just using a funciton/native?
I know that if we do make a variable out of a handle, it's required for recycling the handle's index and the 4 byte the pointer consumes (and of course destroy them first), but why not just use for example GetTriggerUnit() directly?
I don't doubt that it is better, just that I'm curious about why...

*Yeah yeah, not triggers and players...

Another embarassing question;
Why does handle-pointers leak, while direct-pointer (integer, real, boolean, string, code etc) doesn't? I've been told that local versions of these direct-pointers are cleaned up in the end of the function, but I fail to see how global variables are cleaned later on.
Yes and one more while I'm at it; How much data does one of these direct-pointers consume?
__________________
I have no signature yet
Cheezeman is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 07-24-2009, 07:28 PM   #2
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,375

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

Quote:
Originally Posted by Cheezeman
Just like the title says, I'm kind of embarrassed to ask this question
How is it better to attach all* handles to a variable and then null them in the end, than just using a funciton/native?

You don't attach them. You set the variable to point to them. Variables are set, whereas you only attach objects to other objects. (Just terminology.)

Quote:
I know that if we do make a variable out of a handle, it's required for recycling the handle's index and the 4 byte the pointer consumes (and of course destroy them first), but why not just use for example GetTriggerUnit() directly?
I don't doubt that it is better, just that I'm curious about why...

GetTriggerUnit() vs. u - u is far faster to type. Use it a dozen times in a function, and it really adds up. Plus it's a tiny bit faster, probably, but GetTriggerUnit is lightning fast anyway. If I only use GetTriggerUnit() a very small number of times, I'll just use that.

Quote:
Another embarassing question;
Why does handle-pointers leak, while direct-pointer (integer, real, boolean, string, code etc) doesn't? I've been told that local versions of these direct-pointers are cleaned up in the end of the function, but I fail to see how global variables are cleaned later on.

There is no such thing as a direct pointer. A pointer is something that points to an object. Integer, real, boolean are not pointers. The variables hold the data in 4 bytes directly, but do not have any objects they point ot. Code and string do, but that's handled differently to handles (strings don't have reference counters and are always cached, and code is obviously never recycled but loaded at map init).

Anyway, the data of the locals is cleaned up, where that is the pointer or the integer/real/boolean data. Note that the object that the pointer is pointing to is not cleaned up. Due to a bug in WC3's code, when this clean up is done, handles that are pointed to by local variables do not have their reference counters decremented properly, so you have to manually set them to null.

Quote:
Yes and one more while I'm at it; How much data does one of these direct-pointers consume?

All variables have 4 bytes for the data or the address (for pointers) and then consume a little bit more for accessing the variable.
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 07-24-2009, 07:57 PM   #3
Cheezeman
User
 
Cheezeman's Avatar
 
Join Date: Apr 2009
Posts: 179

Cheezeman has little to show at this moment (1)

Default

In conclusion:
1: We set a variable to a handle because it's easier to type and and helps you organize your code (it's also a tiny bit faster, but not much)
2: In difference to handle-pointers, integers reals etc contains data and arn't just pointers to a memmory index (or memmory stock or whatever...)
3: All variables consume 4 bytes until nulled or automaticall trashed (???)

N.o 3 led me to another question: Are integers, reals etc really removed from memmory when not used anymore, or do they keep consuming 4 bytes of data?
__________________
I have no signature yet
Cheezeman is offline   Reply With Quote
Old 07-24-2009, 10:15 PM   #4
Blubb-Tec
Full Metal Mapping!
 
Blubb-Tec's Avatar
 
Join Date: Nov 2006
Posts: 270

Submissions (1)

Blubb-Tec will become famous soon enough (37)Blubb-Tec will become famous soon enough (37)

Default

to no. 3:
whenever a integer/real etc 'leaves scope', that means e.g. a local variable, and the function ends, they are removed, and consume no more space. of course, global integers/reals etc. consume their space until the end of the game. but thats more or less intentional, and you can ignore that
__________________
P A R T Y

"In a way, we're all troubled adolescent girls... deep inside."
Blubb-Tec is offline   Reply With Quote
Old 07-24-2009, 11:27 PM   #5
Cheezeman
User
 
Cheezeman's Avatar
 
Join Date: Apr 2009
Posts: 179

Cheezeman has little to show at this moment (1)

Default

Quote:
Originally Posted by Blubb-Tec
to no. 3:
whenever a integer/real etc 'leaves scope', that means e.g. a local variable, and the function ends, they are removed, and consume no more space. of course, global integers/reals etc. consume their space until the end of the game. but thats more or less intentional, and you can ignore that
Well, I figured that 4 bytes of data won't ever make a big difference, even if we fill 50,000 globals with a value it's like 200kb memmory, out of (avrg) 2GB ram (they are stored in RAM, right?).

And another two questions were spawned from this...
1: Is there a way to null integers, reals, booleans, strings and code?
2: What's the 'common name' for these variable types. I know that for example unit variables are called handle-pointers, but not these 'direct' variables

I'd like to give you rep for the help, but I can't (have to spread first)
__________________
I have no signature yet

Last edited by Cheezeman : 07-24-2009 at 11:28 PM.
Cheezeman is offline   Reply With Quote
Old 07-25-2009, 02:37 AM   #6
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Quote:
Originally Posted by Cheezeman
Well, I figured that 4 bytes of data won't ever make a big difference, even if we fill 50,000 globals with a value it's like 200kb memmory, out of (avrg) 2GB ram (they are stored in RAM, right?).

And another two questions were spawned from this...
1: Is there a way to null integers, reals, booleans, strings and code?
2: What's the 'common name' for these variable types. I know that for example unit variables are called handle-pointers, but not these 'direct' variables

I'd like to give you rep for the help, but I can't (have to spread first)

1. Because the former three are not pointers, the terminology "null" doesn't even apply. However, the latter two are pointers. I haven't tested with code, but strings can be nulled. As they are immutable and not ref-counted, nulling will have no effect though.
2. They could be called scalar types or value types. Strictly speaking, string and code are pointer types or reference types in terms of definition.

Last edited by ToukoAozaki : 07-25-2009 at 02:38 AM.
ToukoAozaki is offline   Reply With Quote
Old 07-25-2009, 02:38 AM   #7
Pyrogasm
Lackadaisically Absent.
 
Pyrogasm's Avatar


Respected User
 
Join Date: Sep 2006
Posts: 4,523

Submissions (9)

Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)

Hero Contest - Fourth place

Send a message via ICQ to Pyrogasm Send a message via AIM to Pyrogasm Send a message via MSN to Pyrogasm Send a message via Yahoo to Pyrogasm
Default

You can null strings by setting them ="", but the others you cannot do anything about, nor do you need to. They're collectively called "Primitives."
__________________
Quote:
Originally posted by Rising_Dusk
Your spells are mostly ignored because they are not very cool so we aren't very excited to review/approve them, but you are incredibly persistent and won't give us an excuse to graveyard it. That is generally what results in a resource being ignored for a long time.

The Spell Request Thread Done for, unless someone else wants to revive it...
It lasted a damn long time.

Please; Ask for Help Appropriately














Quote:
Originally posted by Kyrbi0
Huh. Almost makes me wish I had a girlfriend, to take advantage of today (wait, no, that's not what I meant... I mean, take advantage of the fact that it is international women's day... gah, never mind).
Quote:
Originally posted by Pyrogasm
Rome may not have been built in a day, but the Romans sure as hell didn't say "look at this great city we built guys!" when they had nothing more than a bit of stone and some cottages.
Pyrogasm is offline   Reply With Quote
Old 07-25-2009, 03:21 AM   #8
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,375

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

Quote:
Originally Posted by Cheezeman
3: All variables consume 4 bytes until nulled or automaticall trashed (???)

'All' variables' means all variables (at least after initialisation; arrays are a bit odd and init in blocks of powers of two, and no one has ever tested non-arrays because there's no damned point). A nulled variable just has a data value of 0. Only local variables are dynamically destroyed (out of variables), and they are always destroyed at the end of the function, regardless of what you do.

Quote:
N.o 3 led me to another question: Are integers, reals etc really removed from memmory when not used anymore, or do they keep consuming 4 bytes of data?

This question makes no sense. They are not used....they are not objects. The variable has the integer/real/boolean value from the bits of the 4 bytes, which are dealt with as above.



Quote:
to no. 3:
whenever a integer/real etc 'leaves scope', that means e.g. a local variable, and the function ends, they are removed, and consume no more space. of course, global integers/reals etc. consume their space until the end of the game. but thats more or less intentional, and you can ignore that

Integers/reals cannot 'leave scope'. See above - they are not objects. Integer/etc variables can, and only in the case of local variables.
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women

Last edited by Captain Griffen : 07-25-2009 at 03:23 AM.
Captain Griffen is offline   Reply With Quote
Old 07-25-2009, 02:57 PM   #9
Cheezeman
User
 
Cheezeman's Avatar
 
Join Date: Apr 2009
Posts: 179

Cheezeman has little to show at this moment (1)

Default

Thanks guys, this really helped me.
No further questions have been spawned from your answers.
Reputation to you all
__________________
I have no signature yet
Cheezeman is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 01:41 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services