This file is indexed.

/usr/include/deal.II/base/memory_consumption.h is in libdeal.ii-dev 6.3.1-1.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
//---------------------------------------------------------------------------
//    $Id: memory_consumption.h 19306 2009-08-18 18:41:27Z bangerth $
//    Version: $Name$
//
//    Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//---------------------------------------------------------------------------
#ifndef __deal2__memory_consumption_h
#define __deal2__memory_consumption_h


#include <base/config.h>
#include <base/std_cxx1x/shared_ptr.h>
#include <string>
#include <vector>
#include <utility>

DEAL_II_NAMESPACE_OPEN


/**
 * This namespace provides functions helping to determine the amount
 * of memory used by objects. The goal is not necessarily to give the
 * amount of memory used up to the last bit (what is the memory used
 * by an STL <tt>std::map<></tt> object?), but rather to aid in the search for
 * memory bottlenecks.
 *
 * The functions in this namespace work basically by reducing each
 * object to its basics as far as they are known from this place. They
 * do not attempt to know what goes on in each object, if they are not
 * basic types (such as <tt>int</tt> or <tt>double</tt>) or STL containers (such
 * as <tt>vectors</tt>). The method goes as follows: if the object with
 * which a <tt>memory_consumption</tt> function from this namespace is an
 * atomic type, the return its size by applying the <tt>sizeof</tt>
 * operator to it. If this is not the case, then try to reduce it to
 * more basic types.
 *
 * For example, if it is a C-style array or a standard C++ <tt>std::vector</tt>,
 * then sum up the sizes of the array elements by calling
 * <tt>memory_consumption</tt> on each of them. This way, we can also
 * reduce objects of type <tt>std::vector<std::vector<double> ></tt> to its atomic
 * types, and can thus determine the memory used even if the sizes of
 * the elements of the outermost vector differ (e.g. the first
 * sub-vector has 3 and the second sub-vector has 10 elements).
 *
 * There are two exceptions to simply adding up the sizes of the
 * subobjects: for C++ <tt>std::vector</tt> objects, we also have to add the
 * size of the vector object, i.e. <tt>sizeof(vector<T>)</tt>, to the sizes
 * of the elements. Secondly, for the most common used vectors, such
 * as <tt>std::vector<double></tt> and <tt>std::vector<unsigned int></tt> we determine the
 * size without a loop but rather directly, since we know that the
 * sizes of the elements are constant.
 *
 * Finally, if we cannot reduce a type <tt>T</tt> further, because it is
 * neither atomic nor a known C++ data type, we call a member function
 * <tt>T::memory_consumption</tt> on it, which we assume to exist. Almost
 * all classes in the deal.II library have such a function. This way,
 * if we call <tt>memory_consumption(v)</tt> on a vector <tt>v</tt> of type
 * <tt>FullMatrix<double></tt>, we first reduce this to a loop in which we
 * call <tt>memory_consumption(v[i])</tt>, and because there is no such
 * function handling this explicitly, we try to call
 * <tt>v[i].memory_consumption()</tt>.
 *
 *
 * <h3>Extending this namespace</h3>
 *
 * The functions in this namespace and the functionality provided by
 * it live on the assumption that there is either a function
 * <tt>memory_consumption(T)</tt> in this namespace determining the amount
 * of memory use by objects of type <tt>T</tt>, or that the class <tt>T</tt> has
 * a function of that name as member function. While the latter is
 * true for almost all class in deal.II, we have only implemented the
 * first kind of functions for the most common data types, such as
 * atomic types, strings, C++ vectors, C-style arrays, and C++
 * pairs. These functions therefore do not cover, for example, C++
 * maps, lists, etc. If you need such functions feel free to implement
 * them and send them to us for inclusion.
 *
 * @ingroup memory
 * @author Wolfgang Bangerth, 2000
 */
namespace MemoryConsumption
{
				   /**
				    * Determine the amount of memory
				    * in bytes consumed by a <tt>bool</tt>
				    * variable.
				    */
  inline
  unsigned int memory_consumption (const bool);

				   /**
				    * Determine the amount of memory
				    * in bytes consumed by a <tt>char</tt>
				    * variable.
				    */
  inline
  unsigned int memory_consumption (const char);

				   /**
				    * Determine the amount of memory
				    * in bytes consumed by a
				    * <tt>short int</tt> variable.
				    */
  inline
  unsigned int memory_consumption (const short int);

				   /**
				    * Determine the amount of memory
				    * in bytes consumed by a
				    * <tt>short unsigned int</tt> variable.
				    */
  inline
  unsigned int memory_consumption (const short unsigned int);

				   /**
				    * Determine the amount of memory
				    * in bytes consumed by a <tt>int</tt>
				    * variable.
				    */
  inline
  unsigned int memory_consumption (const int);

				   /**
				    * Determine the amount of memory
				    * in bytes consumed by a <tt>unsigned int</tt>
				    * variable.
				    */
  inline
  unsigned int memory_consumption (const unsigned int);

				   /**
				    * Determine the amount of memory
				    * in bytes consumed by a <tt>float</tt>
				    * variable.
				    */
  inline
  unsigned int memory_consumption (const float);

				   /**
				    * Determine the amount of memory
				    * in bytes consumed by a <tt>double</tt>
				    * variable.
				    */
  inline
  unsigned int memory_consumption (const double);

				   /**
				    * Determine an estimate of the
				    * amount of memory in bytes
				    * consumed by a <tt>std::string</tt>
				    * variable.
				    */
  inline
  unsigned int memory_consumption (const std::string &s);

				   /**
				    * Determine an estimate of the
				    * amount of memory in bytes
				    * consumed by a <tt>std::vector</tt> of
				    * certain elements. It does so by
				    * looping over all elements of the
				    * vector and determining their
				    * sizes using the
				    * <tt>memory_consumption</tt>
				    * functions. If the elements are
				    * of constant size, there might be
				    * another global function
				    * <tt>memory_consumption</tt> for this
				    * data type or if there is a
				    * member function of that class of
				    * that names that returns a
				    * constant value and the compiler
				    * will unroll this loop so that
				    * the operation is fast. If the
				    * size of the data elements is
				    * variable, for example if they do
				    * memory allocation themselves,
				    * then the operation will
				    * necessarily be more expensive.
				    *
				    * Using the algorithm, in
				    * particular the loop over all
				    * elements, it is possible to also
				    * compute the memory consumption
				    * of vectors of vectors, vectors
				    * of strings, etc, where the
				    * individual elements may have
				    * vastly different sizes.
				    *
				    * Note that this algorithm also
				    * takes into account the size of
				    * elements that are allocated by
				    * this vector but not currently
				    * used.
				    *
				    * For the most commonly used
				    * vectors, there are special
				    * functions that compute the size
				    * without a loop. This also
				    * applies for the special case of
				    * vectors of bools.
				    */
  template <typename T>
  inline
  unsigned int memory_consumption (const std::vector<T> &v);

				   /**
				    * Estimate the amount of memory
				    * (in bytes) occupied by a
				    * C-style array. Since in this
				    * library we do not usually
				    * store simple data elements
				    * like <tt>double</tt>s in such
				    * arrays (but rather use STL
				    * <tt>std::vector</tt>s or deal.II
				    * <tt>Vector</tt> objects), we do not
				    * provide specializations like
				    * for the <tt>std::vector</tt> arrays, but
				    * always use the loop over all
				    * elements.
				    */
  template <typename T, int N>
  inline
  unsigned int memory_consumption (const T (&v)[N]);

				   /**
				    * Specialization of the
				    * determination of the memory
				    * consumption of a vector, here
				    * for a vector of <tt>bool</tt>s.
				    *
				    * This is a special case, as the
				    * bools are not stored
				    * one-by-one, but as a bit
				    * field.
				    */
  inline
  unsigned int memory_consumption (const std::vector<bool> &v);

				   /**
				    * Specialization of the
				    * determination of the memory
				    * consumption of a vector, here
				    * for a vector of <tt>int</tt>s.
				    */
  inline
  unsigned int memory_consumption (const std::vector<int> &v);

				   /**
				    * Specialization of the
				    * determination of the memory
				    * consumption of a vector, here
				    * for a vector of <tt>double</tt>s.
				    */
  inline
  unsigned int memory_consumption (const std::vector<double> &v);

				   /**
				    * Specialization of the
				    * determination of the memory
				    * consumption of a vector, here
				    * for a vector of <tt>float</tt>s.
				    */
  inline
  unsigned int memory_consumption (const std::vector<float> &v);

				   /**
				    * Specialization of the
				    * determination of the memory
				    * consumption of a vector, here
				    * for a vector of <tt>char</tt>s.
				    */
  inline
  unsigned int memory_consumption (const std::vector<char> &v);

				   /**
				    * Specialization of the
				    * determination of the memory
				    * consumption of a vector, here
				    * for a vector of <tt>unsigned char</tt>s.
				    */
  inline
  unsigned int memory_consumption (const std::vector<unsigned char> &v);

				   /**
				    * Specialization of the
				    * determination of the memory
				    * consumption of a vector, here
				    * for a vector of pointers.
				    */
  template <typename T>
  inline
  unsigned int memory_consumption (const std::vector<T *> &v);

				   /**
				    * Specialization of the
				    * determination of the memory
				    * consumption of a vector, here
				    * for a vector of strings. This
				    * function is not necessary from a
				    * strict C++ viewpoint, since it
				    * could be generated, but is
				    * necessary for compatibility with
				    * IBM's xlC 5.0 compiler, and
				    * doesn't harm for other compilers
				    * as well.
				    */
  unsigned int memory_consumption (const std::vector<std::string> &v);


				   /**
				    * Determine an estimate of the
				    * amount of memory in bytes
				    * consumed by a pair of values.
				    */
  template <typename A, typename B>
  inline
  unsigned int memory_consumption (const std::pair<A,B> &p);

				   /**
				    * Return the amount of memory
				    * used by a pointer. Make sure
				    * that you are really interested
				    * in this, and not the amount of
				    * memory required by the object
				    * pointed to.
				    */
  template <typename T>
  inline
  unsigned int memory_consumption (const T * const);

				   /**
				    * Return the amount of memory
				    * used by a pointer. Make sure
				    * that you are really interested
				    * in this, and not the amount of
				    * memory required by the object
				    * pointed to.
				    *
				    * This function is the same as
				    * above, but for non-const
				    * pointers
				    */
  template <typename T>
  inline
  unsigned int memory_consumption (T * const);

				   /**
				    * Return the amount of memory
				    * used by a void pointer. Make
				    * sure that you are really
				    * interested in this, and not
				    * the amount of memory required
				    * by the object pointed to.
				    *
				    * Note that we needed this
				    * function since <tt>void</tt> is no
				    * type and a <tt>void*</tt> is thus
				    * not caught by the general
				    * <tt>T*</tt> template function
				    * above.
				    */
  inline
  unsigned int memory_consumption (void * const);

				   /**
				    * Return the amount of memory used
				    * by a shared pointer. Make
				    * sure that you are really
				    * interested in this, and not the
				    * amount of memory required by the
				    * object pointed to.
				    */
  template <typename T>
  inline
  unsigned int memory_consumption (const std_cxx1x::shared_ptr<T> &);

				   /**
				    * For all other types which are
				    * not explicitly listed: try if
				    * there is a member function
				    * called
				    * <tt>memory_consumption</tt>. If
				    * this is not the case, then the
				    * compiler will in any case
				    * complain that this last exit
				    * does not work.
				    */
  template <typename T>
  inline
  unsigned int memory_consumption (const T &t);
}



// now comes the implementation of these functions

namespace MemoryConsumption
{
  inline
  unsigned int memory_consumption (const bool)
  {
    return sizeof(bool);
  }



  inline
  unsigned int memory_consumption (const char)
  {
    return sizeof(char);
  }



  inline
  unsigned int memory_consumption (const short int)
  {
    return sizeof(short int);
  }



  inline
  unsigned int memory_consumption (const short unsigned int)
  {
    return sizeof(short unsigned int);
  }



  inline
  unsigned int memory_consumption (const int)
  {
    return sizeof(int);
  }



  inline
  unsigned int memory_consumption (const unsigned int)
  {
    return sizeof(unsigned int);
  }



  inline
  unsigned int memory_consumption (const float)
  {
    return sizeof(float);
  }



  inline
  unsigned int memory_consumption (const double)
  {
    return sizeof(double);
  }



  inline
  unsigned int memory_consumption (const std::string &s)
  {
    return sizeof(s) + s.length();
  }



  template <typename T>
  unsigned int memory_consumption (const std::vector<T> &v)
  {
    unsigned int mem = sizeof(std::vector<T>);
    const unsigned int n = v.size();
    for (unsigned int i=0; i<n; ++i)
      mem += memory_consumption(v[i]);
    mem += (v.capacity() - n)*sizeof(T);
    return mem;
  }



  template <typename T, int N>
  unsigned int memory_consumption (const T (&v)[N])
  {
    unsigned int mem = 0;
    for (unsigned int i=0; i<N; ++i)
      mem += memory_consumption(v[i]);
    return mem;
  }



  inline
  unsigned int memory_consumption (const std::vector<bool> &v)
  {
    return v.capacity() / 8 + sizeof(v);
  }



  inline
  unsigned int memory_consumption (const std::vector<int> &v)
  {
    return (v.capacity() * sizeof(int) +
	    sizeof(v));
  }



  inline
  unsigned int memory_consumption (const std::vector<double> &v)
  {
    return (v.capacity() * sizeof(double) +
	    sizeof(v));
  }



  inline
  unsigned int memory_consumption (const std::vector<float> &v)
  {
    return (v.capacity() * sizeof(float) +
	    sizeof(v));
  }



  inline
  unsigned int memory_consumption (const std::vector<char> &v)
  {
    return (v.capacity() * sizeof(char) +
	    sizeof(v));
  }



  inline
  unsigned int memory_consumption (const std::vector<unsigned char> &v)
  {
    return (v.capacity() * sizeof(unsigned char) +
	    sizeof(v));
  }



  template <typename T>
  inline
  unsigned int memory_consumption (const std::vector<T *> &v)
  {
    return (v.capacity() * sizeof(T *) +
	    sizeof(v));
  }



  template <typename A, typename B>
  inline
  unsigned int memory_consumption (const std::pair<A,B> &p)
  {
    return (memory_consumption(p.first) +
	    memory_consumption(p.second));
  }



  template <typename T>
  inline
  unsigned int
  memory_consumption (const T * const)
  {
    return sizeof(T*);
  }



  template <typename T>
  inline
  unsigned int
  memory_consumption (T * const)
  {
    return sizeof(T*);
  }



  inline
  unsigned int
  memory_consumption (void * const)
  {
    return sizeof(void*);
  }



  template <typename T>
  inline
  unsigned int
  memory_consumption (const std_cxx1x::shared_ptr<T> &)
  {
    return sizeof(std_cxx1x::shared_ptr<T>);
  }



  template <typename T>
  inline
  unsigned int
  memory_consumption (const T &t)
  {
    return t.memory_consumption();
  }
}

DEAL_II_NAMESPACE_CLOSE

#endif