This is a little struct attachment system that I made which I called RAS (Reborns Attachment System). It is very easy to use I think.
Since I'm not a pro in vJass there might be some bugs or something.
Here's the code:
vJass
library RAS
privatefunction H2I takeshandle h returnsinteger return h return 0 endfunction
To attach a struct to a handle you just use this: call AttachStruct1(WHICH_HANDLE, THE_STRUCT)
And to retrieve the struct you use this: call GetAttachedStruct1(WHICH_HANDLE)
You may use other numbers than 1 after AttachStruct or GetAttachedStruct, but it must be initialized.
To find out which numbers you may use look at the end of the code.
v1.0 -- Initial Release
v1.1 -- Changed some things to make it safer
v2.0 -- Changed the code (I found some bugs) It also uses textmacros now
v2.0b -- Inlined the functions
Last edited by The_Reborn_Devil; 11-21-2008 at 01:46 PM..
You don't need the ifs. And I would like you to test this vs TimerUtils and CSData. And this method isn't really new, but I must say the test results are impressing.
Yeah, I know. That's why I added it :). I was surprised when I saw the results, because I thought that HSAS was fastest, but both DAS, RAS and CSData was faster than it.
Edit: I have done another benchmark test now, and I've tested: CSData, RAS, TimerUtils Red Flavour and DAS.
Here's the result:
Result
EDIT3: The code is changed so the results might be wrong!
Does it mean that you can only create what: 1000 handles?
No, but the system has to be tweaked a little bit.
I am testing somethings at the moment. I will give a more detailed comment later.
It seemed to do more :D
Well I will put it like this for now:
cache[max1][max2]
The maximum numbers that can go in there are:
max1=8//Not to sure at the moment ;)
max2=1023
Bigger, and data gets confused, but no game errors(crashes) occur.
Notes
library RAS initializer Init
privatefunction H2I takeshandle h returnsinteger return h return 0 endfunction
private type int extendsintegerarray[1000][1000]//useless, actually an error, but the compiler doesn't recognize it, i guess private type int2 extends int array[1000]
globals private int2 cache endglobals
privatefunction Init takesnothingreturnsnothing localinteger i = 1//wrong set cache = int2.create() loop exitwhen i == 1000 set cache[i] = int2.create()//wrong, but doesn't matter set i = i + 1 endloop endfunction
function GetAttachedStruct takeshandle h, integer dat returnsinteger localinteger i = H2I(h) localinteger i2 = i - 0x100000 if i2 < 1000 then//what about dat? return cache[i2][dat] endif return 0 endfunction
function AttachStruct takeshandle h, integer dat, integer str returnsnothing localinteger i = H2I(h) localinteger i2 = i - 0x100000 if i2 < 1000 then//what about dat? set cache[i2][dat] = str endif endfunction endlibrary
So the corrected code would look like this:
Corrected
library RAS initializer Init
privatefunction H2I takeshandle h returnsinteger return h return 0 endfunction
private type int extendsintegerarray[1023] private type int2 extends int array[1023]
globals private int2 cache endglobals
privatefunction Init takesnothingreturnsnothing localinteger i = 0 set cache = int2.create() loop exitwhen i == int2.size//note this set cache[i] = int.create() set i = i + 1 endloop endfunction
function GetAttachedStruct takeshandle h, integer dat returnsinteger localinteger i = H2I(h) localinteger i2 = i - 0x100000 if i2 < int2.size and dat<int.size then//but this check reduces performance return cache[i2][dat] endif return 0 endfunction
function AttachStruct takeshandle h, integer dat, integer str returnsnothing localinteger i = H2I(h) localinteger i2 = i - 0x100000 if i2 < int2.size and dat<int.size then//same set cache[i2][dat] = str endif endfunction endlibrary
But how do you compare it to the other attachment systems?
(I know you use the benchmark system)
But they all work for handle indexes >1000 and the code you posted does not.
I suggest using this:
Suggestion
library RAS initializer Init
privatefunction H2I takeshandle h returnsinteger return h return 0 endfunction
private type int extendsintegerarray[1023] private type int2 extends int array[1023]
privatefunction Init takesnothingreturnsnothing set cache = int2.create() loop exitwhen i == int2.size set cache[i]=int.create() set i = i + 1 endloop endfunction
function GetAttachedStruct takeshandle h returnsinteger set i=H2I(h) - 0x100000 return cache[R2I(i/5191)][i - (i / 5191) * 5191] endfunction
function AttachStruct takeshandle h, integer str returnsnothing set i=H2I(h) - 0x100000 set cache[R2I(i/5191)][i - (i / 5191) * 5191]=str endfunction endlibrary
You can say it is faster than HSAS, but slightly. Those things depend on a lot of factors. For instance, on my HDD and with WC3 1.22 Game cache is the fastest. I think Blizzard modified the game optimizing the game cache so that Dota Allstars can run smother.
However, this will only work indexes up to 8191. To make it work for bigger indexes you should change the line:
private type int extends integer array [1023]
to
private type int extends integer array [1023,409550]
This way it will work up to 409550 indexes, but at the cost of performance, big cost. Even with lower maximum instances speed is drastically reduced.
To attach more than 1 struct to the same handle I suggest doing this the same way as HSAS(with text macros). Something like this:
With macros
library RAS initializer blah
privatefunction H2I takeshandle h returnsinteger return h return 0 endfunction
private type int extendsintegerarray[1023,409550] private type int2 extends int array[1023,10230] globals privateinteger i endglobals //! textmacro RAS takes IDENTIFIER globals private int2 cache$IDENTIFIER$ endglobals
privatefunction Init$IDENTIFIER$ takesnothingreturnsnothing localinteger j = 0 set cache$IDENTIFIER$ = int2.create() loop exitwhen j == int2.size set cache$IDENTIFIER$[j]=int.create() set j = j + 1 endloop endfunction
function GetAttachedStruct$IDENTIFIER$ takeshandle h returnsinteger set i=H2I(h) - 0x100000 return cache$IDENTIFIER$[R2I(i/5191)][i - (i / 5191) *5191] endfunction
function AttachStruct$IDENTIFIER$ takeshandle h, integer str returnsnothing set i=H2I(h) - 0x100000 set cache$IDENTIFIER$[R2I(i/5191)][i - (i / 5191) * 5191]=str endfunction //! endtextmacro
I would have suggested like this, but I found out it does not work:
With an array
library RAS initializer Init
privatefunction H2I takeshandle h returnsinteger return h return 0 endfunction
private type int extendsintegerarray[1023,409550] private type int2 extends int array[1023,10230]
globals private int2 array cache [8] privateinteger i endglobals
privatefunction Init takesnothingreturnsnothing localinteger ij = 0 localinteger j = 0 loop exitwhen j==8 set cache[j] = int2.create() loop exitwhen ij == int2.size set cache[j][ij]=int.create() set ij = ij + 1 endloop set j=j+1 endloop endfunction
function GetAttachedStruct takeshandle h,integer dat returnsinteger set i=H2I(h) - 0x100000 return cache[dat][R2I(i/1023)][i - (i / 1023) * 1023]//here dat may cause a problem, but checking it would reduce performance endfunction
function AttachStruct takeshandle h, integer dat, integer str returnsnothing set i=H2I(h) - 0x100000 set cache[dat][R2I(i/5191)][i - (i / 5191) * 5191]=str//here dat may cause a problem, but checking it would reduce performance endfunction endlibrary
I will do some more tests :P
P.s. And whatever I did, I could not make a 3D array(working).
Edit: I suppose some of this is just junk, but some of it is not :P
For instance, on my HDD and with WC3 1.22 Game cache is the fastest. I think Blizzard modified the game optimizing the game cache so that Dota Allstars can run smother.
Wtf ?!
Could you post your test code and the results with the patch 1.22 and 1.21b plz
Code is from the implemented benchmark system in the the test map from here
Only editing I did was changing the script from testing ABC to testing RAS.
Those 2 are the results I got before 1.22
Single Struct Attachment Speed Test
Multiple Struct Attachment Speed Test
As you can see at that time my HDD performed well vs HSAS but could not beat it. And it is not a high performance one - Seagate 250GB 7200 RPM 16 MB cache. On the market there are hdds that are way faster than this.
And here are the 1.22 results
Single Struct Attachment Speed Test on 1.22
Multiple Struct Attachment Speed Test on 1.22
After the patch, Gama cache beats HSAS. And After I did the last optimization I thought of to RAS it's performance improved a little bit, so that is why it has such a lead over Game cache in the Single Struct Attachment Speed Test.
The exact RAS code I used for the last result is in my previous post in the Suggestion.
Anyway, the benchmark system only check speed and not data integrity.