From 5fb315261b6f77b383525d6a0fec4b2bde2f074f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sun, 24 Jan 2016 22:39:52 +0100 Subject: Work in deva's critique. This branch should now be ready for merge. --- src/drumgizmo.cc | 4 ++-- src/drumgizmo.h | 2 +- src/memchecker.cc | 30 +++++++++++++++--------------- src/memchecker.h | 18 +++++++++++------- 4 files changed, 29 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 44cd73c..e47cab7 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -87,8 +87,8 @@ bool DrumGizmo::loadkit(std::string file) // Check if there is enough free RAM to load the drumkit. if(!memchecker.enoughFreeMemory(kit)) { - ERR(drumgizmo, "Not enough free RAM to load the drumkit."); - return false; + printf("WARNING: There doesn't seem to be enough RAM available to load the kit.\n" + "Trying to load it anyway...\n"); } loader.loadKit(&kit); diff --git a/src/drumgizmo.h b/src/drumgizmo.h index 3f84fdd..f1f570a 100644 --- a/src/drumgizmo.h +++ b/src/drumgizmo.h @@ -102,7 +102,7 @@ protected: AudioCache audioCache; DrumKit kit; - Memchecker memchecker; + MemChecker memchecker; size_t framesize; bool freewheel; diff --git a/src/memchecker.cc b/src/memchecker.cc index b26603a..8c8c183 100644 --- a/src/memchecker.cc +++ b/src/memchecker.cc @@ -27,25 +27,25 @@ #include "memchecker.h" #ifdef WIN32 - #define WIN32_LEAN_AND_MEAN - #include +#define WIN32_LEAN_AND_MEAN +#include #else - #include +#include #endif #include #include -bool Memchecker::enoughFreeMemory(const DrumKit& drumkit) const +bool MemChecker::enoughFreeMemory(const DrumKit& drumkit) const { - size_t freeMemory = calcFreeMemory(); - size_t neededMemory = calcNeededMemory(drumkit); + uint64_t free_memory = calcFreeMemory(); + uint64_t needed_memory = calcNeededMemory(drumkit); - return freeMemory >= neededMemory; + return free_memory >= needed_memory; } -size_t Memchecker::calcFreeMemory() const +uint64_t MemChecker::calcFreeMemory() const { - size_t free_memory(0); + uint64_t free_memory = 0; // Platform specific calculation of the amount of free memory. #ifdef WIN32 @@ -55,18 +55,18 @@ size_t Memchecker::calcFreeMemory() const free_memory = status.ullAvailPhys; #else struct sysinfo sys_info; - sysinfo (&sys_info); + sysinfo(&sys_info); free_memory = sys_info.freeram * sys_info.mem_unit; #endif - DEBUG(memchecker, "Calculated %llu free memory.\n", (long long unsigned int)free_memory); + DEBUG(memchecker, "Calculated %" PRIu64 " free memory.\n", free_memory); return free_memory; } -size_t Memchecker::calcNeededMemory(const DrumKit& drumkit) const +uint64_t MemChecker::calcNeededMemory(const DrumKit& drumkit) const { - size_t needed_memory(0); + uint64_t needed_memory = 0; // Calculate memory usage of all instruments of drumkit. for(auto instrument : drumkit.instruments) @@ -80,12 +80,12 @@ size_t Memchecker::calcNeededMemory(const DrumKit& drumkit) const } } - DEBUG(memchecker, "Calculated %llu needed memory.\n", (long long unsigned int)needed_memory); + DEBUG(memchecker, "Calculated %" PRIu64 " needed memory.\n", needed_memory); return needed_memory; } -size_t Memchecker::calcBytesPerChannel(const std::string& filename) const +uint64_t MemChecker::calcBytesPerChannel(const std::string& filename) const { SF_INFO sf_info; diff --git a/src/memchecker.h b/src/memchecker.h index c3e13c2..f12c3d2 100644 --- a/src/memchecker.h +++ b/src/memchecker.h @@ -29,20 +29,24 @@ #include "drumkit.h" #include +// includes cstdint automatically and is needed for the PRIu64 macro +#include -class Memchecker +class MemChecker { public: - //! Checks if there is enough memory left to load drumkit into RAM. - //! \param drumkit The drumkit for which it is checked if there's enough memory left. - //! \return True iff there is enough memory left. + //! Checks if there is enough memory left to load drumkit into RAM. + //! \param drumkit The drumkit for which it is checked if there's enough memory left. + //! \return True iff there is enough memory left. bool enoughFreeMemory(const DrumKit& drumkit) const; protected: // Computes how much RAM (in bytes) is left. - size_t calcFreeMemory() const; + uint64_t calcFreeMemory() const; + // Computes how much memory the drumkit takes when loaded into RAM (in bytes). - size_t calcNeededMemory(const DrumKit& drumkit) const; + uint64_t calcNeededMemory(const DrumKit& drumkit) const; + // Computes the number of bytes per channel of using libsnd. - size_t calcBytesPerChannel(const std::string& filename) const; + uint64_t calcBytesPerChannel(const std::string& filename) const; }; -- cgit v1.2.3