annotate base/StorageAdviser.h @ 1219:794b64e62e58 msvc2015_64

Tidy and re-fix for Linux
author Chris Cannam
date Wed, 19 Oct 2016 09:11:51 +0100
parents cc27f35aa75c
children adbd16d2c1e8
rev   line source
Chris@334 1
Chris@168 2 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@168 3
Chris@168 4 /*
Chris@168 5 Sonic Visualiser
Chris@168 6 An audio file viewer and annotation editor.
Chris@168 7 Centre for Digital Music, Queen Mary, University of London.
Chris@202 8 This file copyright 2006 QMUL.
Chris@168 9
Chris@168 10 This program is free software; you can redistribute it and/or
Chris@168 11 modify it under the terms of the GNU General Public License as
Chris@168 12 published by the Free Software Foundation; either version 2 of the
Chris@168 13 License, or (at your option) any later version. See the file
Chris@168 14 COPYING included with this distribution for more information.
Chris@168 15 */
Chris@168 16
Chris@168 17 #ifndef _STORAGE_ADVISER_H_
Chris@168 18 #define _STORAGE_ADVISER_H_
Chris@168 19
Chris@1038 20 #include <cstdlib>
Chris@1038 21
Chris@168 22 /**
Chris@168 23 * A utility class designed to help decide whether to store cache data
Chris@168 24 * (for example FFT outputs) in memory or on disk in the TempDirectory.
Chris@170 25 * This is basically a compendium of simple rules of thumb.
Chris@168 26 */
Chris@168 27
Chris@168 28 class StorageAdviser
Chris@168 29 {
Chris@168 30 public:
Chris@168 31 // pass to recommend() zero or more of these OR'd together
Chris@168 32 enum Criteria {
Chris@170 33 NoCriteria = 0,
Chris@170 34 SpeedCritical = 1,
Chris@170 35 PrecisionCritical = 2,
Chris@170 36 LongRetentionLikely = 4,
Chris@170 37 FrequentLookupLikely = 8
Chris@168 38 };
Chris@168 39
Chris@168 40 // recommend() returns one or two of these OR'd together
Chris@168 41 enum Recommendation {
Chris@170 42 NoRecommendation = 0,
Chris@170 43 UseMemory = 1, // Disc is strongly contraindicated
Chris@170 44 PreferMemory = 2, // Either would do; memory probably better
Chris@170 45 PreferDisc = 4, // Either would do; disc probably better
Chris@170 46 UseDisc = 8, // Probably won't fit in memory
Chris@170 47 ConserveSpace = 16,// Whatever you choose, keep it compact
Chris@170 48 UseAsMuchAsYouLike = 32 // Take my advice and there'll be space for all
Chris@168 49 };
Chris@168 50
Chris@169 51 /**
Chris@169 52 * Recommend where to store some data, given certain storage and
Chris@169 53 * recall criteria. The minimum size is the approximate amount of
Chris@170 54 * data in kilobytes that will be stored if the recommendation is
Chris@170 55 * to ConserveSpace; the maximum size is approximately the amount
Chris@169 56 * that will be used if UseAsMuchAsYouLike is returned.
Chris@170 57 *
Chris@170 58 * May throw InsufficientDiscSpace exception if there appears to
Chris@170 59 * be nowhere the minimum amount of data can be stored.
Chris@169 60 */
Chris@168 61 static Recommendation recommend(Criteria criteria,
Chris@1038 62 size_t minimumSize,
Chris@1038 63 size_t maximumSize);
Chris@205 64
Chris@205 65 enum AllocationArea {
Chris@205 66 MemoryAllocation,
Chris@205 67 DiscAllocation
Chris@205 68 };
Chris@205 69
Chris@205 70 /**
Chris@205 71 * Specify that we are planning to use a given amount of storage
Chris@205 72 * (in kilobytes), but haven't allocated it yet.
Chris@205 73 */
Chris@1038 74 static void notifyPlannedAllocation(AllocationArea area, size_t size);
Chris@205 75
Chris@205 76 /**
Chris@205 77 * Specify that we have now allocated, or abandoned the allocation
Chris@205 78 * of, the given amount (in kilobytes) of a storage area that was
Chris@205 79 * previously notified using notifyPlannedAllocation.
Chris@205 80 */
Chris@1038 81 static void notifyDoneAllocation(AllocationArea area, size_t size);
Chris@205 82
Chris@411 83 /**
Chris@411 84 * Force all subsequent recommendations to use the (perhaps
Chris@411 85 * partial) specification given here. If NoRecommendation given
Chris@411 86 * here, this will reset to the default free behaviour.
Chris@411 87 */
Chris@411 88 static void setFixedRecommendation(Recommendation recommendation);
Chris@411 89
Chris@205 90 private:
Chris@1038 91 static size_t m_discPlanned;
Chris@1038 92 static size_t m_memoryPlanned;
Chris@411 93 static Recommendation m_baseRecommendation;
Chris@168 94 };
Chris@168 95
Chris@168 96 #endif
Chris@168 97