[apps/graph] Limited number of cached functions

The caches used for function values memoization are now stored in
ContinuousFunctionStore : there are now only a fixed number, instead of
one per function. This effectively enables caching only for the first
few functions on screen, while reducing the memory usage.

Change-Id: I2ade091717f73a14a756fe527c773db8e8627be7
This commit is contained in:
Gabriel Ozouf
2020-06-09 16:19:23 +02:00
committed by Émilie Feral
parent 95fef86ec0
commit 42fcf557b8
8 changed files with 43 additions and 24 deletions

View File

@@ -5,20 +5,28 @@ namespace Shared {
constexpr int ContinuousFunctionCache::k_sizeOfCache;
constexpr float ContinuousFunctionCache::k_cacheHitTolerance;
constexpr int ContinuousFunctionCache::k_numberOfAvailableCaches;
// public
void ContinuousFunctionCache::PrepareCache(void * f, void * c, float tMin, float tStep) {
void ContinuousFunctionCache::PrepareCache(void * f, void * ctx, void * cch, float tMin, float tStep) {
if (!cch) {
return;
}
ContinuousFunction * function = (ContinuousFunction *)f;
Poincare::Context * context = (Poincare::Context *)c;
ContinuousFunctionCache * functionCache = function->cache();
if (functionCache->filled() && tStep / StepFactor(function) == functionCache->step()) {
Poincare::Context * context = (Poincare::Context *)ctx;
if (!function->cache()) {
ContinuousFunctionCache * cache = (ContinuousFunctionCache *)cch;
cache->clear();
function->setCache(cache);
}
if (function->cache()->filled() && tStep / StepFactor(function) == function->cache()->step()) {
if (function->plotType() == ContinuousFunction::PlotType::Cartesian) {
function->cache()->pan(function, context, tMin);
}
return;
}
functionCache->setRange(function, tMin, tStep);
functionCache->memoize(function, context);
function->cache()->setRange(function, tMin, tStep);
function->cache()->memoize(function, context);
}
void ContinuousFunctionCache::clear() {