diff --git a/src/preferences/advancedsettings.h b/src/preferences/advancedsettings.h index d6c77ab2a..248478235 100644 --- a/src/preferences/advancedsettings.h +++ b/src/preferences/advancedsettings.h @@ -170,7 +170,15 @@ private slots: const Preferences* const pref = Preferences::instance(); // Disk write cache spin_cache.setMinimum(0); - spin_cache.setMaximum(2048); + // When build as 32bit binary, set the maximum at less than 2GB to prevent crashes. + // These macros may not be available on compilers other than MSVC and GCC +#if !defined(_M_X64) || !defined(__amd64__) + //1800MiB to leave 248MiB room to the rest of program data in RAM + spin_cache.setMaximum(1800); +#else + // 4GiB + spin_cache.setMaximum(4*1024); +#endif spin_cache.setValue(pref->diskCacheSize()); updateCacheSpinSuffix(spin_cache.value()); setRow(DISK_CACHE, tr("Disk write cache size"), &spin_cache); diff --git a/src/preferences/preferences.cpp b/src/preferences/preferences.cpp index 7fd19a6a1..3bf25b7e5 100644 --- a/src/preferences/preferences.cpp +++ b/src/preferences/preferences.cpp @@ -1098,11 +1098,37 @@ void Preferences::setShutdownqBTWhenDownloadsComplete(bool shutdown) { } uint Preferences::diskCacheSize() const { - return value("Preferences/Downloads/DiskWriteCacheSize", 0).toUInt(); + uint size = value("Preferences/Downloads/DiskWriteCacheSize", 0).toUInt(); + + // When build as 32bit binary, set the maximum at less than 2GB to prevent crashes. + // These macros may not be available on compilers other than MSVC and GCC +#if !defined(_M_X64) || !defined(__amd64__) + //1800MiB to leave 248MiB room to the rest of program data in RAM + if (size > 1800) + size = 1800; +#else + // 4GiB + if (size > 4*1024) + size = 4*1024; +#endif + + return size; } void Preferences::setDiskCacheSize(uint size) { - setValue("Preferences/Downloads/DiskWriteCacheSize", size); + uint size0 = size; + +#if !defined(_M_X64) || !defined(__amd64__) + //1800MiB to leave 248MiB room to the rest of program data in RAM + if (size0 > 1800) + size0 = 1800; +#else + // 4GiB + if (size0 > 4*1024) + size0 = 4*1024; +#endif + + setValue("Preferences/Downloads/DiskWriteCacheSize", size0); } uint Preferences::diskCacheTTL() const {