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

The Pawn Memory Squeeze


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Technical/Development        Approver:   Emp` (115)
[DeathTV] Sid 6.7
Member
Join Date: Oct 2007
Old 06-19-2008 , 19:28   The Pawn Memory Squeeze
Reply With Quote #1

In Pawn, repeated strings are not represented by the same object or memory like in Java so this is an exercise to remedy that by tossing strings on the heap to stop redundancy in memory and save memory.

This script does two things:
A) Generates a dump file with all the tokenized data first (for fun), then the two string tables at the end of the file. The first one lists all strings and how many times they are repeated, the second one only contains repeated strings that are long enough to be considered. It reports how much memory can be saved by optimizing out everything.
B) Generation of an optimized source code file. Compiling this will make the amxx file take up less resources as reported by the compiler.

To begin processing (after you installed this plugin, of course) call amx_memorysqueeze from console upon a .sma file in your scripting directory.

At the end of processing, a report is generated on how much memory can be saved, and a new file is outputted in scripting with _memsqueeze.sma ending. The strings tossed on the heap should be declared before the very first function. The symbol dump is located in the matching txt file.
This does not have the ability to see around aliases to strings, ex defines, although it is possible.

Notes:
put a #define MEMORYSQUEEZE somewhere in your source file at top, and there will be dumped all the strings placed on the heap. Otherwise it will try to autoguess where the first function is defined and define the replacements immediately before the function.


The following is an example of how good this works, even on the largest plugins.
Quote:
Command: amx_memorysqueeze amx_super.sma
This is on a alpha or beta 4.0 for amx_super.
Welcome to the AMX Mod X 1.76-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team
Header size: 5232 bytes
Code size: 178020 bytes
Data size: 98120 bytes
Stack/heap size: 16384 bytes; max. usage is unknown, due to recursion
Total requirements: 297756 bytes
Done.

Unsqueezed
Welcome to the AMX Mod X 1.76-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team
Header size: 5960 bytes
Code size: 196512 bytes
Data size: 104124 bytes
Stack/heap size: 16384 bytes; max. usage is unknown, due to recursion
Total requirements: 322980 bytes
Done.
If you are interested in code optimization, visit http://wiki.amxmodx.org/Optimizing_P...X_Scripting%29
Attached Files
File Type: sma Get Plugin or Get Source (amx_memorysqueeze.sma - 1849 views - 25.1 KB)
__________________
Power Votes Core << Democracy at your fingertips
Get Mortal Kombat Miscstats for CS

Last edited by [DeathTV] Sid 6.7; 07-21-2008 at 19:36. Reason: minor bugfix
[DeathTV] Sid 6.7 is offline
soccdoodcss
Veteran Member
Join Date: Nov 2006
Location: Wisconsin
Old 06-19-2008 , 19:30   Re: The Pawn Memory Squeeze
Reply With Quote #2

Very interesting! I'll have to take a look into how this works.
__________________
"Now safe beneath their wisdom and their feet.
Here I will teach you truly how to sleep."
soccdoodcss is offline
Send a message via AIM to soccdoodcss
bmann_420
AMX_Super Pooper
Join Date: Jan 2005
Location: [SuperCentral.co]
Old 06-19-2008 , 20:46   Re: The Pawn Memory Squeeze
Reply With Quote #3

Wow, that is an insight and a half man
__________________
bmann_420 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-19-2008 , 22:28   Re: The Pawn Memory Squeeze
Reply With Quote #4

Proof it works

I changed some of what your plugin does into mine (saving memory with strings) and also changed certain variables from "new" to "static".

Here was my result:
[img]http://img167.**************/img167/7808/06192008212554fr0.png[/img]

Thanks
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
atomen
Veteran Member
Join Date: Oct 2006
Location: Stockholm, Sweden
Old 06-20-2008 , 05:09   Re: The Pawn Memory Squeeze
Reply With Quote #5

Actually this is very interesting as soccdoodcss said.
I have to try it asap when I get home from the country side.
__________________
atomen is offline
Send a message via MSN to atomen
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 06-20-2008 , 06:49   Re: The Pawn Memory Squeeze
Reply With Quote #6

A nice file and string manipulation, looks interesting...
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Simon Logic
Senior Member
Join Date: Nov 2006
Location: RF
Old 06-20-2008 , 08:44   Re: The Pawn Memory Squeeze
Reply With Quote #7

Code:
    new itwouldbeironicifididntdothis[] = "amx_memorysqueeze" ... register_concmd(itwouldbeironicifididntdothis,itwouldbeironicifididntdothis,ADMIN_RCON,         "shows how much memory a plugin could save by tossing strings on the heap")


You should mention this plugin is for AMX/X 1.80 & higher only.

I think using such a tool via amx/x is more complex than a separate (console application or standalone script) tool. But i was still impressed
__________________
my modest stuff: AXN 1.6.1 | plugins | bsp2csdm

Last edited by Simon Logic; 06-20-2008 at 08:48.
Simon Logic is offline
Send a message via Skype™ to Simon Logic
iknowiz58
Member
Join Date: Sep 2006
Old 07-18-2008 , 13:12   Re: The Pawn Memory Squeeze
Reply With Quote #8

I have tried this out an it is not working.

- Made sure your plugin was working
- I uploaded the deagsmapmanager.sma to the scripting folder.
- amx_memorysqueeze deagsmapmanager.sma in console
- Got the deagsmapmanger_memorysqueeze.sma
- Downloaded & added #define MEMORYSQUEEZE
- Attempted to compile and got the error
"Could not locate outputfile <compile failed>."

Could you help?

deagsmapmanager_memorysqueeze.sma
__________________

iknowiz58 is offline
[DeathTV] Sid 6.7
Member
Join Date: Oct 2007
Old 07-21-2008 , 19:35   Re: The Pawn Memory Squeeze
Reply With Quote #9

Found the problem. Try the new code and report back
__________________
Power Votes Core << Democracy at your fingertips
Get Mortal Kombat Miscstats for CS
[DeathTV] Sid 6.7 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 10:31.


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