RosettaCodeData/Task/Arena-storage-pool/OxygenBasic/arena-storage-pool.basic

32 lines
548 B
Plaintext

'==============
Class ArenaPool
'==============
string buf
sys pb,ii
method Setup(sys n) as sys {buf=nuls n : pb=strptr buf : ii=0 : return pb}
method Alloc(sys n) as sys {method=pb+ii : ii+=n}
method Empty() {buf="" : pb=0 : ii=0}
end class
macro Create(type,name,qty,pool)
type name[qty] at (pool##.alloc qty * sizeof type)
end macro
'====
'DEMO
'====
ArenaPool pool : pool.setup 1000 * sizeof int
Create int,i,100,pool
Create int,j,100,pool
j[51] <= 1,2,3,4,5
print j[51] j[52] j[53] j[54] j[55] 'result 15
pool.empty