Raised This Month: $95 Target: $400
 23% 

AllocString space recycler


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Admin Commands        Approver:   HamletEagle (33)
Xiaobaibai
Junior Member
Join Date: Dec 2016
Old 07-16-2017 , 11:12   AllocString space recycler
Reply With Quote #1

[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()
Attached Files
File Type: zip AllocString.zip (273 Bytes, 137 views)
File Type: sma Get Plugin or Get Source (x_stringman.sma - 827 views - 1.0 KB)

Last edited by Xiaobaibai; 07-18-2017 at 13:03. Reason: Update sma
Xiaobaibai is offline
543658883
Junior Member
Join Date: Mar 2011
Old 07-16-2017 , 14:18   Re: AllocString space recycler
Reply With Quote #2

nice work buddy
543658883 is offline
JusTGo
Veteran Member
Join Date: Mar 2013
Location: Tunisia
Old 07-17-2017 , 08:53   Re: AllocString space recycler
Reply With Quote #3

i have newbie question lets say the game have both this line codes:

PHP Code:
pev->noiseMoving ALLOC_STRING("common/null.wav");
.
.
.
pev->noiseArrived ALLOC_STRING("common/null.wav"); 
does this mean we can hook FM_AllocString and do the same so it will be allocated only once ? and in other places where ALLOC_STRING is used more then once in some forwards.
__________________
JusTGo is offline
Xiaobaibai
Junior Member
Join Date: Dec 2016
Old 07-17-2017 , 13:03   Re: AllocString space recycler
Reply With Quote #4

Quote:
Originally Posted by JusTGo View Post
i have newbie question lets say the game have both this line codes:

PHP Code:
pev->noiseMoving ALLOC_STRING("common/null.wav");
.
.
.
pev->noiseArrived ALLOC_STRING("common/null.wav"); 
does this mean we can hook FM_AllocString and do the same so it will be allocated only once ? and in other places where ALLOC_STRING is used more then once in some forwards.
Yeah. However, FM_AllocString cannot hook calls from fakemeta like engfunc(EngFunc_AllocString, "info_target");

It can only hook those from mp.dll and so on but not from amxx using fakemeta.
Xiaobaibai is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-17-2017 , 13:55   Re: AllocString space recycler
Reply With Quote #5

For approval:
-destroy the trie in plugin_end.
__________________
HamletEagle is offline
Xiaobaibai
Junior Member
Join Date: Dec 2016
Old 07-18-2017 , 13:03   Re: AllocString space recycler
Reply With Quote #6

Quote:
Originally Posted by HamletEagle View Post
For approval:
-destroy the trie in plugin_end.
Done
Xiaobaibai is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-18-2017 , 13:16   Re: AllocString space recycler
Reply With Quote #7

Approved. I like the ideea.
__________________

Last edited by HamletEagle; 07-18-2017 at 13:16.
HamletEagle is offline
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 07-18-2017 , 19:28   Re: AllocString space recycler
Reply With Quote #8

Quote:
Originally Posted by HamletEagle View Post
For approval:
-destroy the trie in plugin_end.
Is It really necessary to do?
When a map changes, trie Will be destroyed, no?
baneado is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-19-2017 , 10:49   Re: AllocString space recycler
Reply With Quote #9

Quote:
Originally Posted by baneado View Post
Is It really necessary to do?
When a map changes, trie Will be destroyed, no?
I remember Arkshine saying that in amxx < 183 it's not guaranteed to be destroyed. Anyway, you should always free all handles that you use, no matter what.
__________________
HamletEagle is offline
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 07-31-2017 , 11:44   Re: AllocString space recycler
Reply With Quote #10

So, reading more about this plugin:
Quote:
Originally Posted by Xiaobaibai View Post
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.
It only be useful when you are creating entities with fakemeta.
Will It never happen using create_entity with engine?

If so, It must be fixed on fakemeta core...

Last edited by baneado; 07-31-2017 at 11:44.
baneado is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:23.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode