mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-30 00:41:09 +02:00
src/driver/pictureviewer/pictureviewer.cpp add bufferram and cached to calc freemem
Origin commit data
------------------
Commit: 1f0a1bfdf2
Author: Jacek Jendrzej <overx300@gmail.com>
Date: 2017-06-13 (Tue, 13 Jun 2017)
Origin message was:
------------------
src/driver/pictureviewer/pictureviewer.cpp add bufferram and cached to calc freemem
This commit is contained in:
@@ -854,12 +854,38 @@ unsigned char * CPictureViewer::ResizeA(unsigned char *orgin, int ox, int oy, in
|
|||||||
return int_Resize(orgin, ox, oy, dx, dy, COLOR, NULL, true);
|
return int_Resize(orgin, ox, oy, dx, dy, COLOR, NULL, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t getCachedMemSize(void)
|
||||||
|
{
|
||||||
|
FILE *procmeminfo = fopen("/proc/meminfo", "r");
|
||||||
|
size_t cached = 0;
|
||||||
|
if (procmeminfo) {
|
||||||
|
char buf[80] = {0}, a[80] = {0};
|
||||||
|
size_t v = 0;
|
||||||
|
while (fgets(buf, sizeof(buf), procmeminfo)) {
|
||||||
|
char unit[10];
|
||||||
|
*unit = 0;
|
||||||
|
if ((3 == sscanf(buf, "%[^:]: %llu %s", a, &v, unit))
|
||||||
|
|| (2 == sscanf(buf, "%[^:]: %llu", a, &v))) {
|
||||||
|
if (*unit == 'k')
|
||||||
|
v <<= 10;
|
||||||
|
if (!strcasecmp(a, "Cached")){
|
||||||
|
cached = v;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(procmeminfo);
|
||||||
|
}
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
bool CPictureViewer::checkfreemem(size_t bufsize)
|
bool CPictureViewer::checkfreemem(size_t bufsize)
|
||||||
{
|
{
|
||||||
struct sysinfo info;
|
struct sysinfo info;
|
||||||
sysinfo( &info );
|
sysinfo( &info );
|
||||||
if(bufsize + 4096 > (size_t)info.freeram + (size_t)info.freeswap){
|
size_t cached = getCachedMemSize();
|
||||||
dprintf(DEBUG_NORMAL, "[CPictureViewer] [%s - %d] Error: Out of memory: need %zu > free %zu\n", __func__, __LINE__,bufsize,(size_t)info.freeram + (size_t)info.freeswap);
|
if(bufsize + sysconf(_SC_PAGESIZE) > (size_t)info.freeram + (size_t)info.freeswap + (size_t)info.bufferram + cached){
|
||||||
|
dprintf(DEBUG_NORMAL, "[CPictureViewer] [%s - %d] Error: Out of memory: need %zu > free %zu\n", __func__, __LINE__,bufsize,(size_t)info.freeram + (size_t)info.freeswap + (size_t)info.bufferram + cached);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user