Login
Register
Menu
Home
Forum
JassDoc
Types
Functions
Variables
Help
Chat
Media
Search
Search posts
WC3 JASS.com
"The Jass Vault" plus vJASS and Zinc
WC3 Modding Information Center
Forum
Warcraft (WC3) Modding
Warcraft III Resources
Warcraft III Spells and Systems
Codes & Snippets
AllocQ
Warcraft III:
Maps
Models
Skins
Icons
Spells / Systems
Tools
Tutorials
Snippets
JASS vJASS Spells and Systems
Tutorials
Chat @Discord
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation
-
Zinc documentation
-
WC3 Optimizer documentation
AllocQ
Codes & Snippets
Started by
moyack
Views
1532
Replies
0
Users
1
1
Pages:
1
Go Down
0 Members and 1 Guest are viewing this topic.
nestharus
Newbie - level 2
Posts:
23
WC3 Models: 0
WC3 Tutorials: 0
WC3 Tools: 0
WC3 Maps: 0
WC3 Skins: 0
WC3 Icons: 0
WC3 Spells: 0
Reputation:
20
User
AllocQ
on:
March 01, 2012, 04:57:56 PM
Category:
Variables
Language:
vJASS
Related Topics or Resources
ErrorMessage
by
nestharus
Code: jass
library
AllocQ
/* v1.0.1.0
*************************************************************************************
*
* */
uses
/*
*
* */
ErrorMessage
/*
*
*************************************************************************************
*
* Maximizes speed by reducing local variable declarations and removing
* if-statement.
*
* Uses a queue instead of a stack for recycler. Using a queue requires one
* extra variable declaration.
*
* set alloc = recycler[0]
* set recycler[0] = recycler[alloc]
*
************************************************************************************
*
* module AllocQFast
*
* Fields
* -------------------------
*
* readonly boolean isAllocated
*
* Methods
* -------------------------
*
* static method allocate takes nothing returns thistype
* method deallocate takes nothing returns nothing
*
* debug static method calculateMemoryUsage takes nothing returns integer
* debug static method getAllocatedMemoryAsString takes nothing returns string
*
************************************************************************************/
module
AllocQ
/*
* stack
*/
private
static
integer
array
recycler
private
static
integer
alloc
private
static
integer
last = 8191
/*
* list of allocated memory
*/
debug
private
static
integer
array
allocatedNext
debug
private
static
integer
array
allocatedPrev
/*
* free memory counter
*/
debug
private
static
integer
usedMemory = 0
/*
* allocation
*/
static
method
allocate
takes
nothing
returns
thistype
set
alloc = recycler[0]
debug
call
ThrowError(alloc == 0,
"AllocQ"
,
"allocate"
,
"thistype"
, 0,
"Overflow."
)
set
recycler[0] = recycler[alloc]
set
recycler[alloc] = -1
debug
set
usedMemory = usedMemory + 1
debug
set
allocatedNext[alloc] = 0
debug
set
allocatedPrev[alloc] = allocatedPrev[0]
debug
set
allocatedNext[allocatedPrev[0]] = alloc
debug
set
allocatedPrev[0] = alloc
return
alloc
endmethod
method
deallocate
takes
nothing
returns
nothing
debug
call
ThrowError(recycler[
this
] != -1,
"AllocQ"
,
"deallocate"
,
"thistype"
,
this
,
"Attempted To Deallocate Null Instance."
)
set
recycler[last] =
this
set
recycler[
this
] = 0
set
last =
this
debug
set
usedMemory = usedMemory - 1
debug
set
allocatedNext[allocatedPrev[
this
]] = allocatedNext[
this
]
debug
set
allocatedPrev[allocatedNext[
this
]] = allocatedPrev[
this
]
endmethod
/*
* analysis
*/
method
operator
isAllocated
takes
nothing
returns
boolean
return
recycler[
this
] == -1
endmethod
static
if
DEBUG_MODE
then
static
method
calculateMemoryUsage
takes
nothing
returns
integer
return
usedMemory
endmethod
static
method
getAllocatedMemoryAsString
takes
nothing
returns
string
local
integer
memoryCell = allocatedNext[0]
local
string
memoryRepresentation =
null
loop
exitwhen
memoryCell == 0
if
(memoryRepresentation ==
null
)
then
set
memoryRepresentation =
I2S
(memoryCell)
else
set
memoryRepresentation = memoryRepresentation +
", "
+
I2S
(memoryCell)
endif
set
memoryCell = allocatedNext[memoryCell]
endloop
return
memoryRepresentation
endmethod
endif
/*
* initialization
*/
private
static
method
onInit
takes
nothing
returns
nothing
local
integer
i = 0
set
recycler[8191] = 0
//so that the array doesn't reallocate over and over again
loop
set
recycler[i] = i + 1
exitwhen
i == 8190
set
i = i + 1
endloop
endmethod
endmodule
endlibrary
«
Last Edit: December 19, 2017, 12:30:11 AM by moyack
»
Print
Pages:
1
Go Up
« previous
next »
WC3 Modding Information Center
Forum
Warcraft (WC3) Modding
Warcraft III Resources
Warcraft III Spells and Systems
Codes & Snippets
AllocQ
PortaMx-SEF 1.54
|
PortaMx © 2008-2015
,
PortaMx corp.
Search
Username
Password
Always stay logged in
Forgot your password?