[Tutorial] Sparse arrays
#1

Sparse arrays

Introduction
Time after time, I see users using 2D or 3D arrays for string storage - which takes up a LOT of memory. This tutorial will teach you how to limit your use on sparse arrays, as well as save memory in your script.

What is a sparse array?
A sparse array is a multidimensional array which often has most of it's data empty, but it still takes up lots of memory.

Consider this code:

pawn Код:
#define MAX_ITEMS (128)

new g_String[MAX_ITEMS][64];
This array alone is a total of 8,192 cells - which is 32,768 bytes (32 kilobytes). For example, if you are only using 10/128 items, you are using 2,560 bytes, but there's still 29,208 bytes being unused!

However, since we're using global variables, this memory isn't allocated in any way, but the memory is dumped in the assembly line, which makes the .amx size larger in size.

The following data is dumped on the stack:

Код:
DUMP          200 2fc 3f8 4f4 5f0 6ec 7e8 8e4 9e0 adc bd8 cd4 dd0 ecc fc8 10c4
DUMP          11c0 12bc 13b8 14b4 15b0 16ac 17a8 18a4 19a0 1a9c 1b98 1c94 1d90 1e8c 1f88 2084
DUMP          2180 227c 2378 2474 2570 266c 2768 2864 2960 2a5c 2b58 2c54 2d50 2e4c 2f48 3044
DUMP          3140 323c 3338 3434 3530 362c 3728 3824 3920 3a1c 3b18 3c14 3d10 3e0c 3f08 4004
DUMP          4100 41fc 42f8 43f4 44f0 45ec 46e8 47e4 48e0 49dc 4ad8 4bd4 4cd0 4dcc 4ec8 4fc4
DUMP          50c0 51bc 52b8 53b4 54b0 55ac 56a8 57a4 58a0 599c 5a98 5b94 5c90 5d8c 5e88 5f84
DUMP          6080 617c 6278 6374 6470 656c 6668 6764 6860 695c 6a58 6b54 6c50 6d4c 6e48 6f44
DUMP          7040 713c 7238 7334 7430 752c 7628 7724 7820 791c 7a18 7b14 7c10 7d0c 7e08 7f04
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DUMP          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Stack and heap
I won't be going into full detail here, since it's explained in detail in the PAWN Implementers Guide.

The "stack/heap" is simply part of the abstract machine that runs PAWN scripts, which controls and manipulates allocated memory from local variables. Very often, people find themselves using so much heap space that they end up running out and resort to using a "#pragma" instruction - but this is bad pratice!

Consider this variable:

pawn Код:
main()
{
    new var;
}
That variable alone is 1 cell (4 bytes). Arrays are basically "many cells in one", so the bigger array, the more memory you're allocating on the stack.

Local variables
Local variables are simply variables created within other functions or statements. When a function is called, that memory is allocated and used accordingly. On the other hand, global variables are not counted on the stack or heap - but they affect .amx size due to the memory dumps in the assembly line.

Why shouldn't I use a sparse array?
Sparse arrays shouldn't be used because they add unnecessary memory usage to scripts, which take up the heap space (mentioned above). There are much more better ways to store string data.
  • Packed arrays

    Packed arrays store data in each byte, rather than each cell, saving you 4 times less the memory.

    Consider this code:

    pawn Код:
    #define MAX_ITEMS (128)

    new g_String[MAX_ITEMS][64 char];
    This will allocate 2,048 cells on the stack (8,192 bytes, which is a reduction 7 kilobytes!). This isn't as much as bad as regular arrays, but packed arrays were designed for a reason!

    The following methods are ways to manipulate "dynamic memory" in PAWN without touching the stack or heap, but they also allocate memory regardless:

  • Linked lists

    A linked list is a data structure which consists of several nodes, all which represent a special sequence. Each node is composed of a data and a reference to the next node in the sequence.

    There is a library by BigETI that allows the possibility of linked lists in PAWN (frankly, I can't think of anymore). You can find it here:

    https://sampforum.blast.hk/showthread.php?tid=451962

  • Data containers

    A data container allows dynamic memory to be allocated, without having to specify a size for them. This data uses an internal linked list system (as far as I know, correct me if I'm wrong) and it doesn't take up any memory on the stack or heap.

    Here's a plugin for data containers:

    https://sampforum.blast.hk/showthread.php?tid=238844

  • Memory access plugin

    This plugin also allows you to dynamically allocate memory during runtime. It was created by BigETI.

    https://sampforum.blast.hk/showthread.php?tid=451381

  • y_malloc

    There's also y_malloc from YSI, which allows dynamic memory allocation too. It was created by ******.

    https://sampforum.blast.hk/showthread.php?tid=58827

  • Per-player variables

    For example, if you have an array like this:

    pawn Код:
    new g_JailReason[MAX_PLAYERS][128];
    If MAX_PLAYERS is 500, then that's 64,000 cells allocated (256,000 bytes, that's 250 kilobytes) onto the stack! I've seen LOADS of people do this before, so I'm not surprised.

    This is where per-player variables come in! Per-player variables are slower than variables in PAWN, but in this case, you do need them!

  • GVar plugin

    Similar to the same scenario above, however you are not dealing with players. It is not really necessary to use the GVar plugin, but it's just added for the sake of completing this tutorial.

    https://sampforum.blast.hk/showthread.php?tid=151076
Conclusion
This is a small tutorial, but at least you've learned something useful from it today!

Feel free to correct me on any parts of this tutorial that I have explained incorrectly, or not thorough enough.

Edit: Thanks to ****** for reminding me about global variables! It was 4 AM when I originally made this tutorial so that would explain why some parts are not properly explained.
Reply
#2

This is a good read.

Anyway, there is one more way to handle data, by using dynamic memory:
Memory access plugin: https://sampforum.blast.hk/showthread.php?tid=451381
y_malloc: https://sampforum.blast.hk/showthread.php?tid=58827

Also there is a "GVars" plugin available for scripters, which uses almost the same style inbuilt PVars uses: https://sampforum.blast.hk/showthread.php?tid=151076

About the "Linked lists in PAWN" include, each node represents a pointer to the previous and next node, data size, and the data itself.

Good job.
Reply
#3

Thanks!

I'll add those 3 links above to the main post.
Reply
#4

Thank you for making this Tutorial now I learnt about Sparse Array
Reply
#5

I know about the sparse arrays, I'm already using CSTL (vectors) all over in my script including GVars and PVars in some places. There are normal arrays too for speed improvement.

Good info, it'd help the scripters to get their scripts more optimized in the following way.
Reply
#6

Thanks for this, been wanting to optimize my script.
Reply
#7

Updated some things in the main post, check it out!

Quote:
Originally Posted by ******
Посмотреть сообщение
[...]
Ah, I'm always getting confused between those two, thanks for clearing that up! If I recall correctly, functions allocate memory to the stack upon being called, and "return" simply clears it from the stack.

Those "dynamic memory" scripts still do infact take up memory, but since they're coded in C++, I'm not entirely sure, I'll have to read up on it since I never worked with C++ before.

Regarding the MAX_PLAYERS * 20 thing, I actually wrote a similar include that allows the possibility to add strings to a "packed list array" without any indexes a few days ago. However I can't seem to find it!

Gonna check out y_jaggedarray for sure, I actually checked it out last year but that was when I barely understand anything haha.
Reply
#8

Interesting!

Also, where can I learn more about this particular PAWN VM? I'd normally say the PAWN Implementers Guide, but I can't seem to find one for the PAWN 3.2.3664 version, since the one on the CompuPhase site is for PAWN 4.0.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)