comparison audioDB-internals.h @ 610:e21a3db643af

MORE MEMORY SANITY Move the logic tracking which points have been visited already (including the std::set datastructure) into the indexed query codepaths, rather than inside accumulators. This has the effect of drastically reducing the memory used in non-indexed queries, such that the working set for a 500-file database with 100000 vectors total goes from 1.2GB to slightly under 3MB. All this and less code, too!
author mas01cr
date Fri, 28 Aug 2009 17:14:06 +0000
parents 31a1556fc2d6
children b82b90c6445e
comparison
equal deleted inserted replaced
609:368320b31db6 610:e21a3db643af
64 double *l2norm; 64 double *l2norm;
65 double *power_data; 65 double *power_data;
66 double *power; 66 double *power;
67 double *mean_duration; 67 double *mean_duration;
68 } adb_qpointers_internal_t; 68 } adb_qpointers_internal_t;
69
70 /* this struct is for maintaining per-query state. We don't want to
71 * store this stuff in the adb struct itself, because (a) it doesn't
72 * belong there and (b) in principle people might do two queries in
73 * parallel using the same adb handle. (b) is in practice a little
74 * bit academic because at the moment we're seeking all over the disk
75 * using adb->fd, but changing to use pread() might win us
76 * threadsafety eventually.
77 */
78 typedef struct adb_qstate_internal {
79 Accumulator *accumulator;
80 std::set<std::string> *allowed_keys;
81 std::priority_queue<PointPair> *exact_evaluation_queue;
82 LSH *lsh;
83 } adb_qstate_internal_t;
84 69
85 /* this struct is the in-memory representation of the binary 70 /* this struct is the in-memory representation of the binary
86 * information stored at the head of each adb file */ 71 * information stored at the head of each adb file */
87 typedef struct adbheader { 72 typedef struct adbheader {
88 uint32_t magic; 73 uint32_t magic;
166 ((r1.qpos < r2.qpos) || 151 ((r1.qpos < r2.qpos) ||
167 ((r1.qpos == r2.qpos) && (strcmp(r1.key, r2.key) < 0))))); 152 ((r1.qpos == r2.qpos) && (strcmp(r1.key, r2.key) < 0)))));
168 } 153 }
169 } adb_result_triple_lt; 154 } adb_result_triple_lt;
170 155
156 /* this struct is for maintaining per-query state. We don't want to
157 * store this stuff in the adb struct itself, because (a) it doesn't
158 * belong there and (b) in principle people might do two queries in
159 * parallel using the same adb handle. (b) is in practice a little
160 * bit academic because at the moment we're seeking all over the disk
161 * using adb->fd, but changing to use pread() might win us
162 * threadsafety eventually.
163 */
164 typedef struct adb_qstate_internal {
165 Accumulator *accumulator;
166 std::set<std::string> *allowed_keys;
167 std::priority_queue<PointPair> *exact_evaluation_queue;
168 std::set< adb_result_t, adb_result_triple_lt > *set;
169 LSH *lsh;
170 } adb_qstate_internal_t;
171
171 /* We could go gcc-specific here and use typeof() instead of passing 172 /* We could go gcc-specific here and use typeof() instead of passing
172 * in an explicit type. Answers on a postcard as to whether that's a 173 * in an explicit type. Answers on a postcard as to whether that's a
173 * good plan or not. */ 174 * good plan or not. */
174 #define mmap_or_goto_error(type, var, start, length) \ 175 #define mmap_or_goto_error(type, var, start, length) \
175 { void *tmp = mmap(0, length, PROT_READ, MAP_SHARED, adb->fd, (start)); \ 176 { void *tmp = mmap(0, length, PROT_READ, MAP_SHARED, adb->fd, (start)); \