--- a/ObjectMemory.st Wed Mar 16 08:51:12 2016 +0000
+++ b/ObjectMemory.st Fri Mar 18 07:45:27 2016 +0000
@@ -43,6 +43,21 @@
privateIn:ObjectMemory
!
+!ObjectMemory primitiveDefinitions!
+%{
+
+/*
+ * includes, defines, structure definitions
+ * and typedefs come here.
+ */
+
+#ifdef __linux__
+// for mallinfo() etc.
+# include <malloc.h>
+#endif
+%}
+! !
+
!ObjectMemory class methodsFor:'documentation'!
caching
@@ -4875,15 +4890,12 @@
"return the number of bytes allocated (and used) by malloc."
%{ /* NOCONTEXT */
- extern int __stx_malloc_stats();
- long statsArray[3];
- int filled;
-
- filled = __stx_malloc_stats(statsArray, sizeof(statsArray));
- if (filled < 1) {
- RETURN(__mkSmallInteger(0));
- }
- RETURN ( __MKUINT(statsArray[0]));
+#if defined(__linux__)
+ struct mallinfo minfo;
+
+ minfo = mallinfo();
+ RETURN ( __MKUINT(minfo.uordblks));
+#endif
%}.
^ 0
@@ -4892,49 +4904,16 @@
"
!
-mallocStatsArray
- "return the number of bytes allocated (and used) by malloc."
-
- |allStats|
-
-%{
- extern int __stx_malloc_stats();
- long statsArray[30];
- int filled, i;
- OBJ temp;
-
- filled = __stx_malloc_stats(statsArray, sizeof(statsArray));
- if (filled < 1) {
- RETURN(nil);
- }
- allStats = __ARRAY_NEW_INT(filled);
- for (i = 0; i < filled; i++) {
- __arrayVal(allStats)[i] = temp = __MKUINT(statsArray[i]);
- __STORE(allStats, temp);
- }
-
- RETURN ( allStats );
-%}.
- ^ #()
-
- "
- ObjectMemory mallocStatsArray
- "
-!
-
mallocTotal
"return the number of bytes reserved by malloc (may not have been used yet)."
%{ /* NOCONTEXT */
- extern int __stx_malloc_stats();
- long statsArray[3];
- int filled;
-
- filled = __stx_malloc_stats(statsArray, sizeof(statsArray));
- if (filled < 2) {
- RETURN(__mkSmallInteger(0));
- }
- RETURN ( __MKUINT(statsArray[1]));
+#if defined(__linux__)
+ struct mallinfo minfo;
+
+ minfo = mallinfo();
+ RETURN ( __MKUINT(minfo.usmblks));
+#endif
%}.
^ 0
@@ -5365,9 +5344,9 @@
This method may be removed without notice"
%{ /* NOCONTEXT */
- void __malloc_print_stats();
-
- __malloc_print_stats();
+#if defined(__linux__)
+ malloc_info(0, stderr);
+#endif
%}
"
ObjectMemory mallocStatistics