mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-02 11:23:41 +01:00
Memory: refactor, don't cache results
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
#include "memory.h"
|
||||
#include "detection/internal.h"
|
||||
|
||||
void ffDetectMemoryImpl(FFMemoryStorage* memory);
|
||||
|
||||
const FFMemoryStorage* ffDetectMemory()
|
||||
{
|
||||
FF_DETECTION_INTERNAL_GUARD(FFMemoryStorage,
|
||||
ffStrbufInit(&result.error);
|
||||
|
||||
ffDetectMemoryImpl(&result);
|
||||
);
|
||||
}
|
||||
@@ -5,6 +5,6 @@
|
||||
|
||||
#include "detection/storage.h"
|
||||
|
||||
const FFMemoryStorage* ffDetectMemory();
|
||||
void ffDetectMemory(FFMemoryStorage* result);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string.h>
|
||||
#include <mach/mach.h>
|
||||
|
||||
void ffDetectMemoryImpl(FFMemoryStorage* ram)
|
||||
void ffDetectMemory(FFMemoryStorage* ram)
|
||||
{
|
||||
ram->bytesTotal = (uint64_t) ffSysctlGetInt64("hw.memsize", 0);
|
||||
if(ram->bytesTotal == 0)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "memory.h"
|
||||
#include "common/sysctl.h"
|
||||
|
||||
void ffDetectMemoryImpl(FFMemoryStorage* ram)
|
||||
void ffDetectMemory(FFMemoryStorage* ram)
|
||||
{
|
||||
uint32_t pageSize = (uint32_t) ffSysctlGetInt("hw.pagesize", 0);
|
||||
if(pageSize == 0)
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void ffDetectMemoryImpl(FFMemoryStorage* swap)
|
||||
void ffDetectMemory(FFMemoryStorage* ram)
|
||||
{
|
||||
FILE* meminfo = fopen("/proc/meminfo", "r");
|
||||
if(meminfo == NULL)
|
||||
{
|
||||
ffStrbufAppendS(&swap->error, "Failed to open /proc/meminfo");
|
||||
ffStrbufAppendS(&ram->error, "Failed to open /proc/meminfo");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ void ffDetectMemoryImpl(FFMemoryStorage* swap)
|
||||
|
||||
fclose(meminfo);
|
||||
|
||||
swap->bytesTotal = memTotal * (uint64_t) 1024;
|
||||
if(swap->bytesTotal == 0)
|
||||
ffStrbufAppendS(&swap->error, "Failed to read MemTotal");
|
||||
ram->bytesTotal = memTotal * (uint64_t) 1024;
|
||||
if(ram->bytesTotal == 0)
|
||||
ffStrbufAppendS(&ram->error, "Failed to read MemTotal");
|
||||
else
|
||||
swap->bytesUsed = (memTotal + shmem - memFree - buffers - cached - sReclaimable) * (uint64_t) 1024;
|
||||
ram->bytesUsed = (memTotal + shmem - memFree - buffers - cached - sReclaimable) * (uint64_t) 1024;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "memory.h"
|
||||
|
||||
void ffDetectMemoryImpl(FFMemoryStorage* ram)
|
||||
void ffDetectMemory(FFMemoryStorage* ram)
|
||||
{
|
||||
MEMORYSTATUSEX statex = {
|
||||
.dwLength = sizeof(statex),
|
||||
|
||||
Reference in New Issue
Block a user