Skip to content

Commit

Permalink
#pragma:dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
DEntisT committed Aug 17, 2023
1 parent 34e9076 commit bece4ff
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 12 deletions.
25 changes: 25 additions & 0 deletions doc/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ Enable warnings when return reference isn't provided.
#pragma:reqref,true;
```

## `dynamic`
- Default value: `200`

Sets the amount of usable cells in which entity data will be stored. Each entity in PawnScript symbolises one cell, for example, a variable occupies 1 cell and stores all its data inside.

```cpp
#pragma:dynamic,default;
//or
#pragma:dynamic,100; // Must be lower than the default value.
```

Output:

```
Heap space 1204958948 bytes
Entity cells (each) 800 bytes (reserved)
All entity cells 9600 bytes (reserved)
Entity cells (each) 400 bytes (modified)
All entity cells 4800 bytes (modified)
Unused memory: 4800 bytes
Total usage est. 1204968548 bytes
```





Expand Down
Binary file modified scriptfiles/modules/consoletest.ps
Binary file not shown.
17 changes: 17 additions & 0 deletions src/core/index.inc
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,30 @@ stock dpp_compile(const script[])
}
*/

stock dpp_printmem__()
{
dpp_nullcomment();
printf("\tHeap space\t\t%i bytes", heapspace());
printf("\tEntity cells (each)\t\t%i bytes (reserved)", dpp_rescells__*4);
printf("\tAll entity cells\t\t%i bytes (reserved)",dpp_entities__*dpp_rescells__*4);
printf("\tEntity cells (each)\t\t%i bytes (modified)", dpp_maxconst*4);
printf("\tAll entity cells\t\t%i bytes (modified)",dpp_entities__*dpp_maxconst*4);
printf("\tUnused memory:\t%i bytes",dpp_entities__*dpp_rescells__*4-dpp_entities__*dpp_maxconst*4);
dpp_nullcomment();
printf("\tTotal usage est.\t\t%i bytes", heapspace() + dpp_entities__*dpp_rescells__*4);
dpp_nullcomment();
#emit retn
}

stock dpp_compile(const script[])
{
print(" ");
new content[16000];
printf("\tPawnScript %i.%i.%i-R%i\tBrace Inc.", DPP_VERSION_MAJOR,DPP_VERSION_MINOR,DPP_VERSION_PATCH,DPP_VERSION_RELEASE);
printf("\tPawn %d.%02d.%02d\tITB CompuPhase", __Pawn >>> 8, __Pawn & 0xFF, __PawnBuild/*__pawn_build*/); // from YSI
//dpp_print("Interpreter version %i.%i.%i-R%i - by: DEntisT",DPP_VERSION_MAJOR,DPP_VERSION_MINOR,DPP_VERSION_PATCH,DPP_VERSION_RELEASE);
dpp_nullcomment();
dpp_printmem__();
if(fexist("index.dppc")) fremove("index.dppc");
//dpp_print("Compiling \"%s\"...",script);
print(" ");
Expand Down
18 changes: 18 additions & 0 deletions src/modules/interpreter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3535,6 +3535,24 @@ public dpp_processpragma(dirgroup[][],dirargs[][])
}
return 1;
}
////////////////////////////////////////////////
//
// dynamic OPTION
//
////////////////////////////////////////////////
//dpp_printmem__
if(!strcmp(dirargs[0], "dynamic"))
{
if(!dpp_isnumeric(dirargs[1]))
{
dpp_error("Failed to allocate memory; insufficient value passed.",);
return 1;
}

dpp_memory__dyn(strval(dirargs[1]));
dpp_printmem__();
return 1;
}

else
{
Expand Down
47 changes: 35 additions & 12 deletions src/ps_mem.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,21 @@ new dpp_ignoreline=0,File:dpp_indexhandle;
#define dpp_maxformargs 10
//-----------------------------------------------------------
// Constant values (used for initial memory allocation)
#define dpp_maxconst__ 100
#define dpp_maxfuncs__ 200
#define dpp_maxinline__ 100
#define dpp_maxvar__ 100
#define dpp_maxclass__ 100
#define dpp_maxtasks__ 50
#define dpp_maxiter__ 50
#define dpp_maxtag__ 100
#define dpp_maxtypedef__ 50
#define dpp_maxenum__ 20
#define dpp_maxobj__ 100
#define dpp_maxoclass__ 50
#define dpp_entities__ 12
#define dpp_rescells__ 200

#define dpp_maxconst__ dpp_rescells__
#define dpp_maxfuncs__ dpp_rescells__
#define dpp_maxinline__ dpp_rescells__
#define dpp_maxvar__ dpp_rescells__
#define dpp_maxclass__ dpp_rescells__
#define dpp_maxtasks__ dpp_rescells__
#define dpp_maxiter__ dpp_rescells__
#define dpp_maxtag__ dpp_rescells__
#define dpp_maxtypedef__ dpp_rescells__
#define dpp_maxenum__ dpp_rescells__
#define dpp_maxobj__ dpp_rescells__
#define dpp_maxoclass__ dpp_rescells__
// Variables with max values of constants above.
// Used in #pragma to select amount of memory used for each entity.
new dpp_maxconst = dpp_maxconst__;
Expand All @@ -82,6 +85,26 @@ new dpp_maxtypedef = dpp_maxtypedef__;
new dpp_maxenum = dpp_maxenum__;
new dpp_maxobj = dpp_maxobj__;
new dpp_maxoclass = dpp_maxoclass__;
dpp_memory__dyn(dyn)
{
if(dyn>dpp_rescells__)
{
dyn=dpp_rescells__; // Avoid invalid memory addresses and instructions.
}
dpp_maxconst = dyn;
dpp_maxfuncs = dyn;
dpp_maxinline = dyn;
dpp_maxvar = dyn;
dpp_maxclass = dyn;
dpp_maxtasks = dyn;
dpp_maxiter = dyn;
dpp_maxtag = dyn;
dpp_maxtypedef = dyn;
dpp_maxenum = dyn;
dpp_maxobj = dyn;
dpp_maxoclass = dyn;
#emit retn
}
//-----------------------------------------------------------
#define dpp_maxenumvals 100
//-----------------------------------------------------------
Expand Down

0 comments on commit bece4ff

Please sign in to comment.