Raised This Month: $51 Target: $400
 12% 

SET_MODEL


Post New Thread Reply   
 
Thread Tools Display Modes
Solokiller
Senior Member
Join Date: Sep 2015
Old 08-20-2016 , 14:23   Re: SET_MODEL
Reply With Quote #11

The engine's string pool is very inefficient; it allocates memory every time you call it, even if the string was previously allocated.

If you want to implement your own pool, i'd suggest clearing it right before you start using it for a new map, probably in worldspawn's instantiation function to be safe.

The engine parses the string while it copies it, replacing "\\n" with "\n", and "\\<any other character>" with "\\".
To be safe, yours should probably do so as well if you think anything relies on it.

As long as you return strings allocated from your own pool as ( ( byte* ) address ) - gpGlobals->pStringBase you should be fine.

Last edited by Solokiller; 08-20-2016 at 14:25.
Solokiller is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-20-2016 , 14:37   Re: SET_MODEL
Reply With Quote #12

You say it allocates memory every time, isn't the pool already allocated beforehand, and the function just works with this cache?
__________________

Last edited by Arkshine; 08-20-2016 at 14:38.
Arkshine is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 08-20-2016 , 15:48   Re: SET_MODEL
Reply With Quote #13

Quote:
Originally Posted by Solokiller View Post
The engine's string pool is very inefficient; it allocates memory every time you call it, even if the string was previously allocated.
I was afraid of that. If they are only freed at server quit, then it is like a must to, the AMXX must stop calling ALLOC_STRING, and use a hashtable to retrieve its address previously allocated/used then keep flooding the server memory within memory leaks.

Quote:
Originally Posted by Solokiller View Post
If you want to implement your own pool, i'd suggest clearing it right before you start using it for a new map, probably in worldspawn's instantiation function to be safe.
Now I got confused. Then it means that the allocated strings are freed at map change, not at server quit?
If it is freed at server quit, why clean our pool at map start?
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 08-20-2016 at 15:53. Reason: update
addons_zz is offline
Solokiller
Senior Member
Join Date: Sep 2015
Old 08-20-2016 , 15:53   Re: SET_MODEL
Reply With Quote #14

It gets its memory from the hunk, which is preallocated.

If you allocate too much, the game shuts down with a "Hunk_Alloc: failed on %i bytes" error.

The hunk is used for other things too, so you can push the engine to shutdown through several means. Map data also goes through it, as well as engine commands (server commands use malloc). It's mostly used for static stuff from what i can tell, so AllocString is the main user after startup.

Note that the hunk's memory allocation strategy allows it to clear "low" memory on map change. The "Clearing memory" message in the console is what signals this event.
Low memory includes AllocString strings.

Here's a link to WinQuake's zone memory header. It should help to explain how hunk allocations work, though it does not note when low memory is freed. That's rather specific to the game engine being used, so just know that it happens right after the last entity has been removed for the map being changed from, and all models for that map have also been freed.

https://github.com/id-Software/Quake...inQuake/zone.h

This is WinQuake's Host_ClearMemory. It's not exactly like GoldSource's, but everything that's in Quake is in GoldSource too, with the exceptions of the console message being optional and the sv and cl instances not being zeroed out: https://github.com/id-Software/Quake...ke/host.c#L469

Quote:
Originally Posted by addons_zz View Post
Now I got confused. Then it means that the allocated strings are freed at map change, not at server quit?
If it is freed at server quit, why clean our pool at map start?
The strings are freed on map change in the engine. You should clear it to keep its size small, things like targetnames can end up wasting a lot of space. I doubt there are many maps that use specific names like levelord_was_here or something like that.

Last edited by Solokiller; 08-20-2016 at 16:17.
Solokiller is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-20-2016 , 15:58   Re: SET_MODEL
Reply With Quote #15

@addons_zz: I would not say memory leak, this is just a large and shared chunk of memory freed at server quit. But definitively not really suitable for what's currently used.

@Solokiller: Thanks for the infos
__________________

Last edited by Arkshine; 08-20-2016 at 15:59.
Arkshine is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 08-20-2016 , 16:43   Re: SET_MODEL
Reply With Quote #16

Quote:
Originally Posted by Solokiller View Post
The strings are freed on map change in the engine. You should clear it to keep its size small, things like targetnames can end up wasting a lot of space. I doubt there are many maps that use specific names like levelord_was_here or something like that.
Thanks you all for the time. I would say, if the engine clear them on map change, then we do not clear our hashmap within their pointers, we would get something like invalid string access on the next map.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 08-21-2016 at 12:51. Reason: update
addons_zz is offline
Solokiller
Senior Member
Join Date: Sep 2015
Old 08-20-2016 , 17:43   Re: SET_MODEL
Reply With Quote #17

I'm not sure what you mean by that, but if you clear it before any AMX mod level AllocString calls are made for a new map, it'll be fine. Sven Co-op uses a server dll level hash map for its string pool and it gets cleared on map change. I don't recall at what point exactly, but it works just fine.
Solokiller is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 08-20-2016 , 20:37   Re: SET_MODEL
Reply With Quote #18

Quote:
Originally Posted by Solokiller View Post
I'm not sure what you mean by that, but if you clear it before any AMX mod level AllocString calls are made for a new map, it'll be fine.
I was talking about the supposed fix to implement on the AMXX to avoid unnecessary calls to ALLOC_STRING.
Quote:
Originally Posted by Arkshine View Post
For AMXX, I guess we could just create a function wrapping this engine function around an hashmap and then using it everywhere it's needed. Adding it in AMXX API for use with modules as well.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 08-20-2016 at 20:38. Reason: misspelling
addons_zz is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 08-21-2016 , 05:10   Re: SET_MODEL
Reply With Quote #19

Why we should implement engine things in amxmodx?
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-21-2016 , 08:18   Re: SET_MODEL
Reply With Quote #20

Because they are badly designed in engine.
klippy is offline
Reply



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 23:07.


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