Skip to content

Instantly share code, notes, and snippets.

@wmoxam
Created May 20, 2020
Embed
What would you like to do?
CC=/usr/bin/cc
CFLAGS= -I/opt/X11/include -L/opt/X11/lib -std=iso9899:1999 -m64 -O0 -g -fno-builtin \
-pedantic -pedantic-errors \
-march=k8 -mtune=k8 -mieee-fp -mhard-float \
-fno-fast-math -malign-double \
-mstackrealign -mno-mmx \
CPPFLAGS=-D_TS_ERRNO -D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE \
-D_X_OPEN_SOURCE=600
LIBS = -lX11 -lm -lpthread
SRCS = ./mandel_col.c ./not_double_r_col.c \
./linear_inter.c \
./mbrot.c \
../xwin/x_error_handler.c \
../xwin/create_gc.c \
../xwin/create_borderless_topwin.c \
../time_and_date/timediff.c \
../sysinfo/sysmem.c ../sysinfo/sysinfo.c
OBJS = ./mandel_col.o ./not_double_r_col.o \
./linear_inter.o \
./mbrot.o \
../xwin/x_error_handler.o \
../xwin/create_gc.o \
../xwin/create_borderless_topwin.o \
../time_and_date/timediff.o \
../sysinfo/sysmem.o ../sysinfo/sysinfo.o
%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -D USE_SYSCTL_HW_MEMSIZE
xmand: xmand.o $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(CPPFLAGS) $(LIBS)
clean:
rm -f $(OBJS) xmand.o xmand
diff --git a/sysinfo/sysmem.c b/sysinfo/sysmem.c
index 8ab0439..652e14b 100644
--- a/sysinfo/sysmem.c
+++ b/sysinfo/sysmem.c
@@ -10,7 +10,9 @@
* Macro and in addition to enable the XSI extension.
*
*********************************************************************/
+#ifndef USE_SYSCTL_HW_MEMSIZE
#define _XOPEN_SOURCE 600
+#endif
#include <stdio.h>
#include <stdint.h>
@@ -20,13 +22,25 @@
#include <stdint.h>
#include <sys/resource.h>
+#if USE_SYSCTL_HW_MEMSIZE
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
uint64_t system_memory()
{
/* should return the amount of memory available in bytes */
long en;
uint64_t pages, page_size;
- en = sysconf(_SC_PHYS_PAGES);
+ #if USE_SYSCTL_HW_MEMSIZE
+ uint64_t mem;
+ size_t len = sizeof(mem);
+ sysctlbyname("hw.memsize", &mem, &len, NULL, 0);
+ en = mem/sysconf(_SC_PAGE_SIZE);
+ #else
+ en = sysconf(_SC_PHYS_PAGES);
+ #endif
if ( en < 0 ){
perror("sysconf(_SC_PHYS_PAGES) : ");
exit(EXIT_FAILURE);
@wmoxam

This comment has been minimized.

Copy link
Owner Author

@wmoxam wmoxam commented May 20, 2020

Screen Shot 2020-05-20 at 7 34 26 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment