AllocString space recycler
Posted: Sun Nov 21, 2021 7:26 pm
[Purpose]
When we create entities, the general method is just like:
new iEntity = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
When we use some fakemeta natives such as set_pev, the module automatically calls EngFunc_AllocString to put the string into the memory.
Notice the EngFunc_AllocString, it acts just like : new char[strlen(szValue)+1];
But without delete operation.
This unlimited allocing operation will finally lead to Cache_TryAlloc error and then the server crashes.
[Method]
So here we'd better to recycle those string pointers.
1.Hook EngFunc_AllocString
2.Puts new string to memory using original call and store the result
3.When we need the same string, return the result from previous call
[Installion]
Since register_forward can't hook calls from engfunc, orpheu(or other module) is need, which can be downloaded in https://forums.alliedmods.net/showthread.php?t=116393
Download x_stringman.sma and compile it...and install it.
And you need the function information(no need for signature), put AllocString file into cstrike/addons/amxmodx/configs/orpheu/functions
[CVARs and configs]
None.
[Changelog]
ver 1.1: Destroy Trie in plugin_end()
Allocstring.zip
get plugin or get source
When we create entities, the general method is just like:
new iEntity = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
When we use some fakemeta natives such as set_pev, the module automatically calls EngFunc_AllocString to put the string into the memory.
Notice the EngFunc_AllocString, it acts just like : new char[strlen(szValue)+1];
But without delete operation.
This unlimited allocing operation will finally lead to Cache_TryAlloc error and then the server crashes.
[Method]
So here we'd better to recycle those string pointers.
1.Hook EngFunc_AllocString
2.Puts new string to memory using original call and store the result
3.When we need the same string, return the result from previous call
[Installion]
Since register_forward can't hook calls from engfunc, orpheu(or other module) is need, which can be downloaded in https://forums.alliedmods.net/showthread.php?t=116393
Download x_stringman.sma and compile it...and install it.
And you need the function information(no need for signature), put AllocString file into cstrike/addons/amxmodx/configs/orpheu/functions
[CVARs and configs]
None.
[Changelog]
ver 1.1: Destroy Trie in plugin_end()
Allocstring.zip
get plugin or get source