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