[Bf-blender-cvs] [fccb42c41f8] master: Fix T63981: Factory default memory cache limit is 4096 MB (32bit builds)

Sergey Sharybin noreply at git.blender.org
Fri May 17 15:10:33 CEST 2019


Commit: fccb42c41f89d64bf0c7ebd75d315adba4a9a927
Author: Sergey Sharybin
Date:   Fri May 17 15:02:12 2019 +0200
Branches: master
https://developer.blender.org/rBfccb42c41f89d64bf0c7ebd75d315adba4a9a927

Fix T63981: Factory default memory cache limit is 4096 MB (32bit builds)

very straightforward: initialize default to the same hard limit as the
RNA properties.

Annoying part is that it's not trivial to make RNA to use same BLI functions,
so leaving that behind for now.

===================================================================

M	source/blender/blenlib/BLI_system.h
M	source/blender/blenlib/intern/system.c
M	source/blender/blenloader/intern/versioning_defaults.c

===================================================================

diff --git a/source/blender/blenlib/BLI_system.h b/source/blender/blenlib/BLI_system.h
index 93ad0e1e70f..f4c0399e959 100644
--- a/source/blender/blenlib/BLI_system.h
+++ b/source/blender/blenlib/BLI_system.h
@@ -41,6 +41,10 @@ char *BLI_cpu_brand_string(void);
  */
 void BLI_hostname_get(char *buffer, size_t bufsize);
 
+/* Get maximum addressable memory in megabytes. */
+size_t BLI_system_memory_max_in_megabytes(void);
+int BLI_system_memory_max_in_megabytes_int(void);
+
 /* getpid */
 #ifdef WIN32
 #  define BLI_SYSTEM_PID_H <process.h>
diff --git a/source/blender/blenlib/intern/system.c b/source/blender/blenlib/intern/system.c
index d23b45a3937..3348912f02a 100644
--- a/source/blender/blenlib/intern/system.c
+++ b/source/blender/blenlib/intern/system.c
@@ -18,10 +18,12 @@
  * \ingroup bli
  */
 
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 #include "BLI_utildefines.h"
+#include "BLI_math_base.h"
 #include "BLI_system.h"
 #include "BLI_string.h"
 
@@ -189,3 +191,20 @@ void BLI_hostname_get(char *buffer, size_t bufsize)
   }
 #endif
 }
+
+size_t BLI_system_memory_max_in_megabytes(void)
+{
+  /* Maximum addressable bytes on this platform.
+   *
+   * NOTE: Due to the shift arithmetic this is a half of the memory. */
+  const size_t limit_bytes_half = (((size_t)1) << ((sizeof(size_t) * 8) - 1));
+  /* Convert it to megabytes and return. */
+  return (limit_bytes_half >> 20) * 2;
+}
+
+int BLI_system_memory_max_in_megabytes_int(void)
+{
+  const size_t limit_megabytes = BLI_system_memory_max_in_megabytes();
+  /* NOTE: The result will fit into integer. */
+  return (int)min_zz(limit_megabytes, (size_t)INT_MAX);
+}
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index 61623a0cade..0e5e37e54a9 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -96,7 +96,7 @@ void BLO_update_defaults_userpref_blend(void)
   /* Only enable tooltips translation by default,
    * without actually enabling translation itself, for now. */
   U.transopts = USER_TR_TOOLTIPS;
-  U.memcachelimit = 4096;
+  U.memcachelimit = min_ii(BLI_system_memory_max_in_megabytes_int() / 2, 4096);
 
   /* Auto perspective. */
   U.uiflag |= USER_AUTOPERSP;



More information about the Bf-blender-cvs mailing list