请选择 进入手机版 | 继续访问电脑版

 找回密码
 点一下
查看: 3397|回复: 16

简单的timer系统(GC,数组两版……) [已修正]

[复制链接]
发表于 2009-9-1 23:06:34 | 显示全部楼层 |阅读模式
用GC做存储的系统的话
很容易因为使用过多的计时器而导致string泄露
恩恩……
这个泄露实际上就是用了过多的timer
于是用于存储的handle值字符串过多而出现的
于是做了个简单的系统:
[jass]
globals  
integer udg_Head = 0
integer udg_Exist = 0
timer array udg_TimerList
endglobals
function LoadTimer takes nothing returns timer
    set udg_TimerList[udg_Head] = null
    if udg_Exist == 0 then
        return CreateTimer()
    endif   
    set udg_Head = udg_Head + 1
    if udg_Head == 8190 then
        set udg_Head = 0
    endif
    set udg_Exist = udg_Exist - 1
    return udg_TimerList[udg_Head]
endfunction
function SaveTimer takes timer t returns nothing
    if udg_Exist == 8190 then
        call DestroyTimer(t)
        return
    endif
    set udg_TimerList[(udg_Head + udg_Exist) - (udg_Head + udg_Exist) / 8190 * 8190] = t
    set udg_Exist = udg_Exist + 1
endfunction
[/jass]
如以上函数
使用也很简单
用LoadTimer获得timer
用SaveTimer排泄即可

如果想使用数组的存储系统
[jass]
globals  
integer udg_Head = 0
integer udg_UsedTimerNum = -1
timer array udg_UseTimer
timer array udg_TimerList
endglobals
function StartDoing takes nothing returns nothing
    local integer i = 0
    loop
        set udg_UseTimer = CreateTimer()
        set i = i + 1
        exitwhen i == 8190
    endloop
endfunction
function LoadTimer takes nothing returns timer
    if udg_Head == 0 then
        if udg_UsedTimerNum == 8190 then
            return null
        endif
        set udg_UsedTimerNum = udg_UsedTimerNum + 1
        return udg_UseTimer[udg_UsedTimerNum]
    endif   
    set udg_Head = udg_Head - 1
    return udg_TimerList[udg_Head]
endfunction
function SaveTimer takes timer t returns nothing
    call PauseTimer(t)
    set udg_TimerList[udg_Head] = t
    set udg_Head = udg_Head + 1
endfunction[/jass]

游戏初始化时执行StartDoing,
此系统存储结构类似handle,有数组8192上限
然后使用方法同GC的
用获得的timer的handle值对8190的模的余数作为存储数组的序号即可

GC版无同时运行timer上限,数组的有8191个timer为上限

以上函数未经测试……
纯属虚构……
如有问题……
纯属失误……

评分

参与人数 1威望 +5 收起 理由
血戮魔动冰 + 5 array的

查看全部评分

发表于 2009-9-1 23:25:50 | 显示全部楼层
默写的~真棒
回复

使用道具 举报

 楼主| 发表于 2009-9-1 23:27:28 | 显示全部楼层
用了JassCraft啦……
回复

使用道具 举报

发表于 2009-9-1 23:32:28 | 显示全部楼层
额。哦。
失望+1
回复

使用道具 举报

发表于 2009-9-2 01:14:27 | 显示全部楼层
1.24的hashtable出现后,gc在国外几乎步入遗忘地带,有空写下trackable的应用教程也不错...
回复

使用道具 举报

发表于 2009-9-2 09:28:33 | 显示全部楼层
trackable至今仍处于只看到过别人用自己还没有尝试过的阶段………………
回复

使用道具 举报

发表于 2009-9-2 09:51:31 | 显示全部楼层
trackable实在是没什么意思的说
回复

使用道具 举报

发表于 2009-9-2 12:38:22 | 显示全部楼层
这些不早就有很多了吗
回复

使用道具 举报

发表于 2009-9-2 13:19:47 | 显示全部楼层
其实是看得懂的不用,想用的看不懂
回复

使用道具 举报

发表于 2009-9-2 21:56:36 | 显示全部楼层
为啥我一点也没看出比TDS好在哪里……疯人兄请简述一下这玩意儿的优点在何处……
回复

使用道具 举报

 楼主| 发表于 2009-9-2 22:03:22 | 显示全部楼层
我也不知道
就是突然想起来……
唯一的好处就是简单
回复

使用道具 举报

发表于 2010-7-31 16:44:39 | 显示全部楼层
可以举个例子吗??。。

这样实在是看不懂。。。。。

用LoadTimer获得timer
用SaveTimer排泄即可

我要什么情况 用LoadTimer获得timer??
然后在哪里 用SaveTimer排泄即可。。。

一头雾水!
回复

使用道具 举报

 楼主| 发表于 2010-7-31 20:27:56 | 显示全部楼层
自己都忘记了,这个系统说白了就是循环使用有限和timer,以减少string泄露(GC)那版
数组版的作用是,可以用timer的Handle值模8190作为绑定数据在数组中的序号,而不会有冲突存在
回复

使用道具 举报

发表于 2010-7-31 22:38:28 | 显示全部楼层
(udg_Head + udg_Exist) - (udg_Head + udg_Exist) / 8190 * 8190
这个取模的意图我很费解...
回复

使用道具 举报

发表于 2010-7-31 22:46:43 | 显示全部楼层
五一左右被囚禁时,胡乱写过一个全局数组的GC\\HT替代物。
发生哈希冲突的位置会生成一个location组成的链表...
回复

使用道具 举报

 楼主| 发表于 2010-7-31 23:34:07 | 显示全部楼层
我忘记了当时的相当,这个是复制的,好像错了,有时间再处理吧
回复

使用道具 举报

 楼主| 发表于 2010-8-3 10:57:04 | 显示全部楼层
已经修正,
原来的两个版本的函数弄混了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-3-29 03:06 , Processed in 0.117528 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表