New memory subsystem.
All checks were successful
The build was successful.

This is a new memory subsystem implementing heap calculations as well as new builtin functions:
 * get_memory_usage()
 * get_memory_peak_usage()
 * get_memory_limit()
It also allows to set an upper memory limit, ensuring that processed script will not be able to allocate more memory from OS.
New subsystem is based on work done in 'memory_limit' branch. Big thanks to devnexen!
This finally fixes #25.
This commit is contained in:
2018-08-18 19:24:38 +02:00
parent 08c47b7528
commit 4dbd3ea412
5 changed files with 185 additions and 47 deletions

View File

@@ -120,6 +120,36 @@ static sxi32 EngineConfig(ph7 *pEngine, sxi32 nOp, va_list ap) {
}
break;
}
case PH7_CONFIG_MEM_LIMIT: {
char *sMemLimit = va_arg(ap, char *);
if(!sMemLimit) {
break;
}
char *sLimitRem;
sxu64 nMemLimit;
SyStrToInt64(sMemLimit, SyStrlen(sMemLimit), (void *)&nMemLimit, &sLimitRem);
if(sLimitRem) {
switch(*sLimitRem) {
case 'G':
case 'g':
nMemLimit *= 1024;
case 'M':
case 'm':
nMemLimit *= 1024;
case 'K':
case 'k':
nMemLimit *= 1024;
}
}
if(nMemLimit >= 1048576) {
/* At least 1MB of heap */
pEngine->sAllocator.pHeap->nLimit = nMemLimit;
} else {
/* Fallback to no limit */
pEngine->sAllocator.pHeap->nLimit = 0;
}
break;
}
case PH7_CONFIG_ERR_ABORT:
/* Reserved for future use */
break;