HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Dynamic Array System

09-13-2006, 03:02 PM#1
BertTheJasser
I have alot of trubble with this code. After some time, everything that uses my dynamic array system (inspired from Vexorian, Thx very much), stops working, the functions stop going on when calling "CreateArray".

Plx help me.
Thx to every answer that may fix the problems.

If you want to use it ( when the bug is hopefully fixed), just mention me, BertTheJasser and Vexorian in the maps credits section.

Collapse JASS:
//starting value of udg_BTJarray1[0]=0
//starting value of udg_BTJarray1[1]=10 //for some private funcs
//staring value of all other udg_BTJarraysX are 0

globals
integer array udg_BTJarray1
integer array udg_BTJarray2
integer array udg_BTJarray3
gameache BTJcache
endglobals

constant function H2I takes handle h returns integer
return h
return 0
endfunction

function BTJcache takes nothing returns gamecache
if udg_BTJcache==null then
    call FlushGameCache(InitGameCache("cachexbtj"))
    set udg_BTJcache=InitGameCache("cachexbtj")
endif
return udg_BTJcache
endfunction

function NewArray takes integer size,boolean nullify returns integer
local integer a=0
local integer b
local integer y //==next
local boolean e=false
set size=size+3
loop
    set y=udg_BTJarray1[a+2] //get the next array of the current array
    if a+size<=y-udg_BTJarray1[a+1] or y==0 then //exit if enough place
        set e=true
        exitwhen true
    endif
    set a=y
    exitwhen a>8192
endloop
if not e then
    loop
        set y=udg_BTJarray2[a-8190]
        if a+size<=y-udg_BTJarray2[a-8191] or y==0 then
            set e=true
            exitwhen true
        endif
        set a=y
        exitwhen a>16384
    endloop
    if not e then
        loop
            set y=udg_BTJarray3[a-16382]
            if a+size<=y-udg_BTJarray3[a-16383] or y==0 then
                set e=true
                exitwhen true
            endif
            set a=y
            exitwhen a>24576
        endloop
        if not e then
            loop
                set y=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]2")
                if a+size<=y-GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]1") or y==0 then
                    set e=true
                    exitwhen true
                endif
                set a=y
            endloop
        endif
    endif
endif

//***Create the new "array"
//-just to get the right size of the array
if 8192>=a then
    set b=a+udg_BTJarray1[a+1]
elseif 16384>=a then
    set b=a+udg_BTJarray2[a-8191]
elseif 24576>=a then
    set b=a+udg_BTJarray3[a-16383]
else
    set b=a+GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]1")
endif

//***set the values[last,size,next] of the new "array"
//-last
if 8192>=b then
    set udg_BTJarray1[b]=a
elseif 16384>=b then
    set udg_BTJarray2[b-8192]=a
elseif 24576>=b then
    set udg_BTJarray3[b-16384]=a
else
    call StoreInteger(BTJcache(),"[array]"+I2S(b),"[index]0",a)
endif

//-size
if 8192>=b then
    set udg_BTJarray1[b+1]=size
elseif 16384>=b then
    set udg_BTJarray2[b-8191]=size
elseif 24576>=b then
    set udg_BTJarray3[b-16383]=size
else
    call StoreInteger(BTJcache(),"[array]"+I2S(b),"[index]1",size)
endif

//-next
if 8192>=b then
    set udg_BTJarray1[b+2]=y //added a +2
elseif 16384>=b then
    set udg_BTJarray2[b-8190]=y
elseif 24576>=b then
    set udg_BTJarray3[b-16382]=y
else
    call StoreInteger(BTJcache(),"[array]"+I2S(b),"[index]2",y)
endif

//***update the links from the last and the next to the current array
//-last to current
if 8192>=a then
    set udg_BTJarray1[a+2]=b
elseif 16384>=a then
    set udg_BTJarray2[a-8190]=b
elseif 24576>=a then
    set udg_BTJarray3[a-16382]=b
else
    call StoreInteger(BTJcache(),"[array]"+I2S(a),"[index]2",b)
endif

//-next to current
if 8192>=y then
    set udg_BTJarray1[y]=b
elseif 16384>=y then
    set udg_BTJarray2[y-8192]=b
elseif 24576>=y then
    set udg_BTJarray3[y-16384]=b
else
    call StoreInteger(BTJcache(),"[array]"+I2S(y),"[index]0",b)
endif
if b<0 then
   return -b
endif
return b
endfunction


function DestroyArray takes integer a returns nothing
local integer last
local integer size
local integer next
//get the values [last,size,next]
if a<=8192 then
    set last=udg_BTJarray1[a]
    set size=udg_BTJarray1[a+1]
    set next=udg_BTJarray1[a+2]
    set udg_BTJarray1[a]=0
    set udg_BTJarray1[a+1]=0
    set udg_BTJarray1[a+2]=0
elseif a<=16384 then
    set last=udg_BTJarray2[a-8192]
    set size=udg_BTJarray2[a-8191]
    set next=udg_BTJarray2[a-8190]
    set udg_BTJarray2[a-8192]=0
    set udg_BTJarray2[a-8191]=0
    set udg_BTJarray2[a-8190]=0
elseif a<=24576 then
    set last=udg_BTJarray3[a-16384]
    set size=udg_BTJarray3[a-16383]
    set next=udg_BTJarray3[a-16382]
    set udg_BTJarray3[a-16384]=0
    set udg_BTJarray3[a-16383]=0
    set udg_BTJarray3[a-16382]=0
else
    set last=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]0")
    set size=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]1")
    set next=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]2")
    //call FlushStoredInteger(udg_BTJcache,"[array]"+I2S(a),"[index]0")
    //call FlushStoredInteger(udg_BTJcache,"[array]"+I2S(a),"[index]1")
    //call FlushStoredInteger(udg_BTJcache,"[array]"+I2S(a),"[index]2")
endif
call FlushStoredMission(BTJcache(),"[array]"+I2S(a)) //in case strings were used
//update the last's next value
if last<=8192 then
    set udg_BTJarray1[last+2]=next
elseif last<=16384 then
    set udg_BTJarray2[last-8190]=next
elseif last<=24576 then
    set udg_BTJarray3[last-16382]=next
else
    call StoreInteger(BTJcache(),"[array]"+I2S(last),"[index]2",next)
endif
//update the next's last value(if existant)
if next<=0 then
elseif next<=8192 then
    set udg_BTJarray1[next]=last
elseif next<=16384 then
    set udg_BTJarray2[next-8192]=last
elseif next<=24576 then
    set udg_BTJarray3[next-16384]=last
else
    call StoreInteger(BTJcache(),"[array]"+I2S(next),"[index]0",next)
endif
endfunction

//String
function SetArrayString takes integer a,integer i,string val returns nothing
call StoreString(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i),val)
endfunction

function GetArrayString takes integer a,integer i returns string
return GetStoredString(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i))
endfunction

//Int
function SetArrayInt takes integer a,integer i,integer val returns nothing
local integer k=a+i+3
if k<=8192 then
    set udg_BTJarray1[k]=val
elseif k<=16384 then
    set udg_BTJarray2[k-8192]=val
elseif k<=24576 then
    set udg_BTJarray3[k-16384]=val
else
    call StoreInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i),val)
endif
endfunction

function GetArrayInt takes integer a,integer i returns integer
local integer k=a+i+3 //i MUST be greater than 0
if k<=8192 then
    return udg_BTJarray1[k]
elseif k<=16384 then
    return udg_BTJarray2[k-8192]
elseif k<=24576 then
    return udg_BTJarray3[k-16384]
else
    return GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i))
endif
return 0
endfunction

//Real

function SetArrayReal takes integer a,integer i,real val returns nothing
local integer k=a+i+3
local integer wal=R2I(val*1000.)
if k<=8192 then
    set udg_BTJarray1[k]=wal
elseif k<=16384 then
    set udg_BTJarray2[k-8192]=wal
elseif k<=24576 then
    set udg_BTJarray3[k-16384]=wal
else
    call StoreInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i),wal)
endif
endfunction

function GetArrayReal takes integer a,integer i returns real
local integer k=a+i+3 //i MUST be greater than 0
local real val=0.
if k<=8192 then
    set val=udg_BTJarray1[k]
elseif k<=16384 then
    set val=udg_BTJarray2[k-8192]
elseif k<=24576 then
    set val=udg_BTJarray3[k-16384]
else
    set val=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i))
endif
if val!=0. then
    return val/1000. 
endif
return 0.
endfunction

//Handle

function SetArrayHandle takes integer a,integer i,handle val returns integer
local integer k=a+i+3
local integer wal=H2I(val)
if k<=8192 then
    set udg_BTJarray1[k]=wal
elseif k<=16384 then
    set udg_BTJarray2[k-8192]=wal
elseif k<=24576 then
    set udg_BTJarray3[k-16384]=wal
else
    call StoreInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i),wal)
endif
return wal
endfunction

//many direct return-bug-exploiters follow in the style of the one that returns a handle.

Post Scriptum:
I know that the arguemt boolean nullify is not cosidered, as I thought, the part of the func which considered the arguument was the reason for the crashes and bugs, but the problem kept occuring again and again.
09-13-2006, 03:40 PM#2
blu_da_noob
Most of your comparison signs are the wrong way. They are currently >= should be <=.
09-13-2006, 04:23 PM#3
Vexorian
the numbers are also invenrted so 2<=3 is the same as 3>=2
09-13-2006, 06:02 PM#4
BertTheJasser
Plx refer by a aquote to the depending places or say from line x to lin y every z is wrong. Thx.

EDIT: I guess this was the reasn for bugging like hell on mass spell usage:
Collapse JASS:
if 8192>=a then
    set udg_BTJarray1[a+2]=b
elseif 16384>=a then
    set udg_BTJarray2[a-8190]=b
elseif 24576>=a then
    set udg_BTJarray3[a-16382]=b
else
    call StoreInteger(BTJcache(),"[array]"+I2S(a),"[index]2",b)
endif
Now replaced with:
Collapse JASS:
if 8192>=a+2 then
    set udg_BTJarray1[a+2]=b
elseif 16384>=a+2 then
    set udg_BTJarray2[a-8190]=b
elseif 24576>=a+2 then
    set udg_BTJarray3[a-16382]=b
else
    call StoreInteger(BTJcache(),"[array]"+I2S(a),"[index]2",b)
endif
Small difference, big effect.
EDIT: The truth: It still bugs around.
09-13-2006, 07:27 PM#5
blu_da_noob
Eh, I could've sworn I saw it the other way. You still might end up with problems with that +2 btw, you could store out of range.
09-14-2006, 01:21 AM#6
Deckname
Use assert-like functions to make sure all values are in the correct range.

As far as i can see, this code is automated-test testable.
Create a function where you use your functions and mak sure that every return value etc is correct.

This makes detecting bugs much easier.

I use this technique to find bugs, too.
You can find my assert implementation (Debug.j) + examples(test_LinkedList etc) in my post here:
LinkedList
09-15-2006, 12:22 PM#7
BertTheJasser
@ Deckname: I am not keen on using checks a in the final version of my game... surly with your method I found some spells that used more slots I primary calculated for them. I just forgot to update the size of the array.
I got around some more bugs, so this is a version which should work relatively "well":
Collapse JASS:
constant function H2I takes handle h returns integer
return h
return 0
endfunction

function BTJcache takes nothing returns gamecache
if udg_BTJcache==null then
    call FlushGameCache(InitGameCache("BTJCACHE"))
    set udg_BTJcache=InitGameCache("BTJCACHE")
endif
return udg_BTJcache
endfunction

function NewArray takes integer size,boolean nullify returns integer
local integer a=0
local integer b
local integer y //==next
local boolean e=false
set size=size+3
loop
    set y=udg_BTJarray1[a+2] //get the next array of the current array
    if a+size<=y-udg_BTJarray1[a+1] or y==0 then //exit if enough place
        set e=true
        exitwhen true
    endif
    set a=y
    exitwhen a>8190
endloop
if not e then
    loop
        set y=udg_BTJarray2[a-8190]
        if a+size<=y-udg_BTJarray2[a-8191] or y==0 then
            set e=true
            exitwhen true
        endif
        set a=y
        exitwhen a>16382
    endloop
    if not e then
        loop
            set y=udg_BTJarray3[a-16382]
            if a+size<y-udg_BTJarray3[a-16383] or y==0 then
                set e=true
                exitwhen true
            endif
            set a=y
            exitwhen a>24574
        endloop
        if not e then
            loop
                set y=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]2")
                if a+size<=y-GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]1") or y==0 then
                    set e=true
                    exitwhen true
                endif
                set a=y
            endloop
        endif
    endif
endif

//***Create the new "array"
//-just to get the right size of the array
if 8192>a+1 then
    set b=a+udg_BTJarray1[a+1]
elseif 16384>a+1 then
    set b=a+udg_BTJarray2[a-8191]
elseif 24576>a+1 then
    set b=a+udg_BTJarray3[a-16383]
else
    set b=a+GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]1")
endif

//***set the values[last,size,next] of the new "array"
//-last
if 8192>b then
    set udg_BTJarray1[b]=a
elseif 16384>b then
    set udg_BTJarray2[b-8192]=a
elseif 24576>b then
    set udg_BTJarray3[b-16384]=a
else
    call StoreInteger(BTJcache(),"[array]"+I2S(b),"[index]0",a)
endif

//-size
if 8192>b+1 then
    set udg_BTJarray1[b+1]=size
elseif 16384>b+1 then
    set udg_BTJarray2[b-8191]=size
elseif 24576>b+1 then
    set udg_BTJarray3[b-16383]=size
else
    call StoreInteger(BTJcache(),"[array]"+I2S(b),"[index]1",size)
endif

//-next
if 8192>b+2 then
    set udg_BTJarray1[b+2]=y //added a +2
elseif 16384>b+2 then
    set udg_BTJarray2[b-8190]=y
elseif 24576>b+2 then
    set udg_BTJarray3[b-16382]=y
else
    call StoreInteger(BTJcache(),"[array]"+I2S(b),"[index]2",y)
endif

//***update the links from the last and the next to the current array
//-last to current
if 8192>a+2 then
    set udg_BTJarray1[a+2]=b
elseif 16384>a+2 then
    set udg_BTJarray2[a-8190]=b
elseif 24576>a+2 then
    set udg_BTJarray3[a-16382]=b
else
    call StoreInteger(BTJcache(),"[array]"+I2S(a),"[index]2",b)
endif

//-next to current
if 8192>y then
    set udg_BTJarray1[y]=b
elseif 16384>y then
    set udg_BTJarray2[y-8192]=b
elseif 24576>y then
    set udg_BTJarray3[y-16384]=b
else
    call StoreInteger(BTJcache(),"[array]"+I2S(y),"[index]0",b)
endif
call Msg("Array "+I2S(b)+" of size "+I2S(size))
if b<0 then
   return GetRandomInt(24576,9999999)
endif
return b
endfunction


function DestroyArray takes integer a returns nothing
local integer last
local integer size
local integer next

local integer b=a+1
local integer c=a+2
//get the values [last,size,next]


if a<8192 then
    set last=udg_BTJarray1[a]
    set udg_BTJarray1[a]=0
elseif a<16384 then
    set last=udg_BTJarray2[a-8192]
    set udg_BTJarray2[a-8192]=0
elseif a<24576 then
    set last=udg_BTJarray3[a-16384]
    set udg_BTJarray3[a-16384]=0
else
    set last=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]0")
endif

if b<8192 then
    set size=udg_BTJarray1[b]
    set udg_BTJarray1[b]=0
elseif b<16384 then
    set size=udg_BTJarray2[b-8192]
    set udg_BTJarray2[b-8192]=0
elseif b<24576 then
    set size=udg_BTJarray3[b-16384]
    set udg_BTJarray3[b-16384]=0
else
    set size=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]1")
endif

if c<8192 then
    set next=udg_BTJarray1[c]
    set udg_BTJarray1[c]=0
elseif c<16384 then
    set next=udg_BTJarray2[c-8192]
    set udg_BTJarray2[c-8192]=0
elseif c<24576 then
    set next=udg_BTJarray3[c-16384]
    set udg_BTJarray3[c-16384]=0
else
    set next=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]2")
endif

call FlushStoredMission(BTJcache(),"[array]"+I2S(a)) //in case strings were used

//update the last's next value
if last<8192 then
    set udg_BTJarray1[last+2]=next
elseif last<16384 then
    set udg_BTJarray2[last-8190]=next
elseif last<24576 then
    set udg_BTJarray3[last-16382]=next
else
    call StoreInteger(BTJcache(),"[array]"+I2S(last),"[index]2",next)
endif


//update the next's last value(if existant)
if next<=0 then
elseif next<8192 then
    set udg_BTJarray1[next]=last
elseif next<16384 then
    set udg_BTJarray2[next-8192]=last
elseif next<24576 then
    set udg_BTJarray3[next-16384]=last
else
    call StoreInteger(BTJcache(),"[array]"+I2S(next),"[index]0",next)
endif
endfunction

//String
function SetArrayString takes integer a,integer i,string val returns nothing
call StoreString(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i),val)
endfunction

function GetArrayString takes integer a,integer i returns string
return GetStoredString(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i))
endfunction

//Int
function SetArrayInt takes integer a,integer i,integer val returns nothing
local integer k=a+i+3
if k<8192 then
    set udg_BTJarray1[k]=val
elseif k<16384 then
    set udg_BTJarray2[k-8192]=val
elseif k<24576 then
    set udg_BTJarray3[k-16384]=val
else
    call StoreInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i),val)
endif
endfunction

function GetArrayInt takes integer a,integer i returns integer
local integer k=a+i+3 //i MUST be greater than 0
if k<8192 then
    return udg_BTJarray1[k]
elseif k<16384 then
    return udg_BTJarray2[k-8192]
elseif k<24576 then
    return udg_BTJarray3[k-16384]
else
    return GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i))
endif
return 0
endfunction

//Real

function SetArrayReal takes integer a,integer i,real val returns nothing
local integer k=a+i+3
local integer wal=R2I(val*1000.)
if k<8192 then
    set udg_BTJarray1[k]=wal
elseif k<16384 then
    set udg_BTJarray2[k-8192]=wal
elseif k<24576 then
    set udg_BTJarray3[k-16384]=wal
else
    call StoreInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i),wal)
endif
endfunction

function GetArrayReal takes integer a,integer i returns real
local integer k=a+i+3 //i MUST be greater than 0
local real val=0.
if k<8192 then
    set val=udg_BTJarray1[k]
elseif k<16384 then
    set val=udg_BTJarray2[k-8192]
elseif k<24576 then
    set val=udg_BTJarray3[k-16384]
else
    set val=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i))
endif
if val!=0. then
    return val/1000. 
endif
return 0.
endfunction

//Handle

function SetArrayHandle takes integer a,integer i,handle val returns integer
local integer k=a+i+3
local integer wal=H2I(val)
if k<8192 then
    set udg_BTJarray1[k]=wal
elseif k<16384 then
    set udg_BTJarray2[k-8192]=wal
elseif k<24576 then
    set udg_BTJarray3[k-16384]=wal
else
    call StoreInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i),wal)
endif
return wal
endfunction

function GetArrayWidget takes integer a,integer i returns widget
local integer b=a+i+3
if b<8192 then
    set bj_forLoopAIndex=udg_BTJarray1[b]
elseif b<16384 then
    set bj_forLoopAIndex=udg_BTJarray2[b-8192]
elseif b<24576 then
    set bj_forLoopAIndex=udg_BTJarray3[b-16384]
else
    set bj_forLoopAIndex=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i))
endif
return bj_forLoopAIndex
return null
endfunction

ERROR: Sometimes starts counting the array indeices from 0 again
09-17-2006, 10:11 AM#8
BertTheJasser
Here we go.

The following version of the code bugs out when the you reach a number higher than 8191 the second time. So if anyone can tell my why...
Collapse JASS:
function Msg takes string s returns nothing
call DisplayTimedTextToPlayer(GetLocalPlayer(),0.,0.,120.,s)
endfunction

constant function H2I takes handle h returns integer
return h
return 0
endfunction

function InitArraySys takes nothing returns nothing
local integer i=0
loop
    set udg_BTJarray1[i]=0
    set udg_BTJarray2[i]=0
    set udg_BTJarray3[i]=0
    set i=i+1
    exitwhen i>8191
endloop
set udg_BTJarray1[0]=10
set udg_BTJarray1[1]=0
endfunction

function InitAttachSys takes nothing returns nothing
local integer i=0
loop
    set udg_BTJat1[i]=0
    set udg_BTJat2[i]=0
    set i=i+1
    exitwhen i>8191
endloop
endfunction

function BTJcache takes nothing returns gamecache
if udg_BTJcache==null then
    call FlushGameCache(InitGameCache("BTJXYZ"))
    set udg_BTJcache=InitGameCache("BTJXYZ")
    call ExecuteFunc("InitArraySys")
    call ExecuteFunc("InitAttachSys")
endif
return udg_BTJcache
endfunction
// data:
// [0] [size]
// [1] [next]
// [2] [last]

function NewArray takes integer size,boolean nullify returns integer
 local integer nx=0
 local integer cur=0
 local integer new=0
 local boolean e=false
    set size=size+3
call Msg("|cFF00FF00part1=="+I2S(cur)+"|r")
    loop
        set nx=udg_BTJarray1[cur+1] //get the next array of the current array [cur+1]
call Msg("next1("+I2S(cur)+")=="+I2S(nx))
        set e= cur+size+udg_BTJarray1[cur]<=nx or nx<=0 //exit if enough place [cur]
        exitwhen e
        set cur=nx
        exitwhen cur>=8191
    endloop
    if cur==8191 and not e then
        set nx=udg_BTJarray2[0] //get the next array of the current array [cur+1]
call Msg("next12("+I2S(cur)+")=="+I2S(nx))
        set e= cur+size+udg_BTJarray1[8191]<=nx or nx<=0 //exit if enough place [cur]
        if not e then
            set cur=nx
        endif
    endif
//***bugging start***
    if not e then
call Msg("|cFF0000FFpart2=="+I2S(cur)+"|r")
        loop
            set nx=udg_BTJarray2[cur-8191] //[cur+1-8192]
call Msg("next2("+I2S(cur)+")=="+I2S(nx))
            set e= cur+size+udg_BTJarray1[cur-8192]<=nx or nx<=0 //exit if enough place [cur]
            exitwhen e
            set cur=nx
            exitwhen cur>=16383
        endloop
        if cur==16383 and not e then
            set nx=udg_BTJarray3[0] //get the next array of the current array [cur+1]
call Msg("next23("+I2S(cur)+")=="+I2S(nx))
            set e= cur+size+udg_BTJarray2[8191]<=nx or nx<=0 //exit if enough place [cur]
            if not e then
                set cur=nx
            endif
        endif

        if not e then
call Msg("|cFFFF0000part3=="+I2S(cur)+"|r")
            loop
                set nx=udg_BTJarray3[cur-16383] //[cur+1-16384]
call Msg("next3("+I2S(cur)+")=="+I2S(nx))
                set e= cur+size+udg_BTJarray1[cur-16384]<=nx or nx<=0 //exit if enough place [cur]
                exitwhen e
                set cur=nx
                exitwhen cur>=24575
            endloop
            if cur==24575 and not e then
                set nx=GetStoredInteger(BTJcache(),"[array]"+I2S(cur),"[size]") //get the next array of the current array [cur+1]
call Msg("next3GC("+I2S(cur)+")=="+I2S(nx))
                set e= cur+size+udg_BTJarray3[8191]<=nx or nx<=0 //exit if enough place [cur]
                if not e then
                    set cur=nx
                endif
            endif

            if not e then
call Msg("|cFF000000partGC=="+I2S(cur)+"|r")
                loop
                    set nx=GetStoredInteger(BTJcache(),"[array]"+I2S(cur),"[next]")
call Msg("nextGC("+I2S(cur)+")=="+I2S(nx))
                    exitwhen cur+size+GetStoredInteger(BTJcache(),"[array]"+I2S(cur),"[size]")<=nx or nx<=0 //exit if enough place
                    set cur=nx
                endloop
            endif
        endif
    endif

    //***Create the new "array"
    //-just to get the right position of the array
    if cur<8192 then
        set new=cur+udg_BTJarray1[cur] // position[cur] + size[cur(0)] = position[new array]
    elseif cur<16384 then
        set new=cur+udg_BTJarray2[cur-8192]
    elseif cur<24576 then
        set new=cur+udg_BTJarray3[cur-16384]
    else
        set new=cur+GetStoredInteger(BTJcache(),"[array]"+I2S(cur),"[size]")
    endif
    
    //***set the values[size,next,last] of the new "array"
    //-size [0]
    if new<8192 then
        set udg_BTJarray1[new]=size
    elseif new<16384 then
        set udg_BTJarray2[new-8192]=size
    elseif new<24576 then
        set udg_BTJarray3[new-16384]=size
    else
        call StoreInteger(BTJcache(),"[array]"+I2S(new),"[size]",size)
    endif
    
    //-next [1]
    if new<8191 then
        set udg_BTJarray1[new+1]=nx
    elseif new<16383 then
        set udg_BTJarray2[new-8191]=nx
    elseif new<24575 then
        set udg_BTJarray3[new-16383]=nx
    else
        call StoreInteger(BTJcache(),"[array]"+I2S(new),"[next]",nx)
    endif

    //-last [2]
    if new<8190 then
        set udg_BTJarray1[new+2]=cur
    elseif new<16382 then
        set udg_BTJarray2[new-8190]=cur
    elseif new<24574 then
        set udg_BTJarray3[new-16382]=cur
    else
        call StoreInteger(BTJcache(),"[array]"+I2S(new),"[last]",cur)
    endif
    
    //***update the link from the last to its next, which is now the current one
    //-last to its next (=new) [1]
    if cur<8191 then
        set udg_BTJarray1[cur+1]=new
    elseif cur<16383 then
        set udg_BTJarray2[cur-8191]=new
    elseif cur<24575 then
        set udg_BTJarray3[cur-16383]=new
    else
        call StoreInteger(BTJcache(),"[array]"+I2S(cur),"[next]",new)
    endif
    //***update the link from the next to the new
    //-next to its last (=new) [2]
    if nx<0 then
    elseif nx<8190 then
        set udg_BTJarray1[nx+2]=new
    elseif nx<16382 then
        set udg_BTJarray2[nx-8190]=new
    elseif nx<24574 then
        set udg_BTJarray3[nx-16382]=new
    else
        call StoreInteger(BTJcache(),"[array]"+I2S(nx),"[last]",new)
    endif
    call Msg("Array "+I2S(new)+" of size "+I2S(size-3))
 return new
endfunction


function DestroyArray takes integer a returns nothing
 local integer last
 local integer size
 local integer next  
    if a<=0 then
        return
    endif     
    //get the values [size(0),next(1),last(2)]
    if a<8192 then
        set size=udg_BTJarray1[a]
        set udg_BTJarray1[a]=0
    elseif a<16384 then
        set size=udg_BTJarray2[a-8192]
        set udg_BTJarray2[a-8192]=0
    elseif a<24576 then
        set size=udg_BTJarray3[a-16384]
        set udg_BTJarray3[a-16384]=0
    else
        set size=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[size]")
    endif
    
    if a<8191 then
        set next=udg_BTJarray1[a+1]
        set udg_BTJarray1[a+1]=0
    elseif a<16383 then
        set next=udg_BTJarray2[a-8191]
        set udg_BTJarray2[a-8191]=0
    elseif a<24575 then
        set next=udg_BTJarray3[a-16383]
        set udg_BTJarray3[a-16383]=0
    else
        set next=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[next]")
    endif
    
    if a<8190 then
        set last=udg_BTJarray1[a+2]
        set udg_BTJarray1[a+2]=0
    elseif a<16382 then
        set last=udg_BTJarray2[a-8190]
        set udg_BTJarray2[a-8190]=0
    elseif a<24574 then
        set last=udg_BTJarray3[a-16382]
        set udg_BTJarray3[a-16382]=0
    else
        set last=GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[last]")
    endif
    
    call FlushStoredMission(BTJcache(),"[array]"+I2S(a)) //in case strings were used
    
    //update the last's next value
    if last<8191 then
        set udg_BTJarray1[last+1]=next
    elseif last<16383 then
        set udg_BTJarray2[last-8191]=next
    elseif last<24575 then
        set udg_BTJarray3[last-16383]=next
    else
        call StoreInteger(BTJcache(),"[array]"+I2S(last),"[next]",next)
    endif
endfunction

//String
function SetArrayString takes integer a,integer i,string val returns nothing
    call StoreString(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i),val)
endfunction

function GetArrayString takes integer a,integer i returns string
 return GetStoredString(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i))
endfunction

//Int
function SetArrayInt takes integer a,integer i,integer val returns nothing
 local integer k=a+i+3
    if k<8192 then
        set udg_BTJarray1[k]=val
    elseif k<16384 then
        set udg_BTJarray2[k-8192]=val
    elseif k<24576 then
        set udg_BTJarray3[k-16384]=val
    else
        call StoreInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i),val)
    endif
endfunction

function GetArrayInt takes integer a,integer i returns integer
 local integer k=a+i+3
    if k<8192 then
     return udg_BTJarray1[k]
    elseif k<16384 then
     return udg_BTJarray2[k-8192]
    elseif k<24576 then
     return udg_BTJarray3[k-16384]
    else
     return GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[index]"+I2S(i))
    endif
 return 0
endfunction
//many many more...

Then I came cross with the hole system, and updated it at the loss of some speed, but well... better it works slow than never.
Collapse JASS:
function Msg takes string s returns nothing
call DisplayTimedTextToPlayer(GetLocalPlayer(),0.,0.,120.,s)
endfunction

constant function H2I takes handle h returns integer
return h
return 0
endfunction

function InitArraySys takes nothing returns nothing
local integer i=0
loop
    set udg_BTJarray1[i]=0
    set udg_BTJarray2[i]=0
    set udg_BTJarray3[i]=0
    set i=i+1
    exitwhen i>8191
endloop
set udg_BTJarray1[0]=10
set udg_BTJarray1[1]=0
endfunction

function InitAttachSys takes nothing returns nothing
local integer i=0
loop
    set udg_BTJat1[i]=0
    set udg_BTJat2[i]=0
    set i=i+1
    exitwhen i>8191
endloop
endfunction

function BTJcache takes nothing returns gamecache
if udg_BTJcache==null then
    call FlushGameCache(InitGameCache("BTJXYZ"))
    set udg_BTJcache=InitGameCache("BTJXYZ")
    call ExecuteFunc("InitArraySys")
    call ExecuteFunc("InitAttachSys")
endif
return udg_BTJcache
endfunction
// data:
// [0] [size]
// [1] [next]
// [2] [last]

function Array_SetSize takes integer a,integer size returns nothing
    if a<8192 then
        set udg_BTJarray1[a]=size
    elseif a<16384 then
        set udg_BTJarray2[a-8192]=size
    elseif a<24576 then
        set udg_BTJarray3[a-16384]=size
    else
        call StoreInteger(BTJcache(),"[array]"+I2S(a),"[size]",size)
    endif
endfunction
function Array_SetNext takes integer a,integer next returns nothing
    if a<8191 then
        set udg_BTJarray1[a+1]=next
    elseif a<16383 then
        set udg_BTJarray2[a-8191]=next
    elseif a<24575 then
        set udg_BTJarray3[a-16383]=next
    else
        call StoreInteger(BTJcache(),"[array]"+I2S(a),"[next]",next)
    endif
endfunction
function Array_SetLast takes integer a,integer last returns nothing
    if a<8190 then
        set udg_BTJarray1[a+2]=last
    elseif a<16382 then
        set udg_BTJarray2[a-8190]=last
    elseif a<24574 then
        set udg_BTJarray3[a-16382]=last
    else
        call StoreInteger(BTJcache(),"[array]"+I2S(a),"[last]",last)
    endif
endfunction

function Array_GetSize takes integer a returns integer
    if a<8192 then
        return udg_BTJarray1[a]
    elseif a<16384 then
        return udg_BTJarray2[a-8192]
    elseif a<24576 then
        return udg_BTJarray3[a-16384]
    endif
return GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[size]")
endfunction
function Array_GetNext takes integer a returns integer
    if a<8191 then
        return udg_BTJarray1[a+1]
    elseif a<16383 then
        return udg_BTJarray2[a-8191]
    elseif a<24575 then
        return udg_BTJarray3[a-16383]
    endif
return GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[next]")
endfunction
function Array_GetLast takes integer a returns integer
    if a<8190 then
        return udg_BTJarray1[a+2]
    elseif a<16382 then
        return udg_BTJarray2[a-8190]
    elseif a<24574 then
        return udg_BTJarray3[a-16382]
    endif
return GetStoredInteger(BTJcache(),"[array]"+I2S(a),"[last]")
endfunction



function NewArray takes integer size,boolean nullify returns integer
 local integer nx=0
 local integer cur=0
 local integer new=0
 local integer i=0
 local boolean e=false
    set size=size+3
    loop
        set nx=Array_GetNext(cur) //get the next array of the current array [cur+1]
        set e= cur+size+Array_GetSize(cur)<=nx or nx<=0 //exit if enough place [cur]
        exitwhen e
        set cur=nx
        set i=i+1
        exitwhen i>8191
    endloop
    if not e then
        set i=0
        loop
            set nx=Array_GetNext(cur) //get the next array of the current array [cur+1]
            set e= cur+size+Array_GetSize(cur)<=nx or nx<=0 //exit if enough place [cur]
            exitwhen e
            set cur=nx
            set i=i+1
            exitwhen i>8191
        endloop
        if not e then
            set i=0
            loop
                set nx=Array_GetNext(cur) //get the next array of the current array [cur+1]
                set e= cur+size+Array_GetSize(cur)<=nx or nx<=0 //exit if enough place [cur]
                exitwhen e
                set cur=nx
                set i=i+1
                exitwhen i>8191
            endloop
        endif
        if not e then
            call Msg("|cffFF0000ERROR|r - |cff999999Array maximum was reached|r")
            return 99999999
        endif
    endif


    set new=cur+Array_GetSize(cur) // position[cur] + size[cur(0)] = position[new array]
  
    call Array_SetSize(new,size)
    call Array_SetNext(new,nx)
    call Array_SetLast(new,cur)
    
    call Array_SetNext(cur,new)
    if nx>=0 then
        call Array_SetLast(nx,new)
    endif
    call Msg("Array "+I2S(new)+" of size "+I2S(size))
 return new
endfunction


function DestroyArray takes integer a returns nothing
 local integer last
 local integer size
 local integer next  
    if a<=0 then
        return
    endif
    //get the values [size(0),next(1),last(2)]
    set size=Array_GetSize(a)
    call Array_SetSize(a,0)

    set next=Array_GetNext(a)
    call Array_SetNext(a,0)

    set last=Array_GetLast(a)
    call Array_SetLast(a,0)
    
    call FlushStoredMission(BTJcache(),"[array]"+I2S(a))
    call Array_SetNext(last,next)
    if next>0 then
        call Array_SetLast(next,last)
    endif
endfunction
//same return funcs as above

Added the 2 test maps.
What to do: Select a unit to create a new arrray. Write "!array" where array is the number of the array you want to destroy (only type in existant arrays).
Attached Files
File type: w3xBTJArraySysBugged.w3x (19.8 KB)
File type: w3xBTJArraySysNew.w3x (18.8 KB)