Main Page   Reference Manual   Namespace List   Compound List   Namespace Members   Compound Members   File Members  

class_alloc.h
Go to the documentation of this file.
1 // $Header$
2 //
3 // Copyright (C) 2000 - 2004, by
4 //
5 // Carlo Wood, Run on IRC <carlo@alinoe.com>
6 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
7 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
8 //
9 // This file may be distributed under the terms of the Q Public License
10 // version 1.0 as appearing in the file LICENSE.QPL included in the
11 // packaging of this file.
12 //
13 
18 #ifndef LIBCWD_CLASS_ALLOC_H
19 #define LIBCWD_CLASS_ALLOC_H
20 
21 #ifndef LIBCWD_CONFIG_H
22 #include <libcwd/config.h>
23 #endif
24 
25 #ifndef LIBCWD_ENUM_MEMBLK_TYPES_H
26 #include <libcwd/enum_memblk_types.h> // Needed for memblk_types_nt.
27 #endif
28 #ifndef LIBCW_LOCKABLE_AUTO_PTR_H
29 #include <libcwd/lockable_auto_ptr.h> // Needed for lockable_auto_ptr<char, true>.
30 #endif
31 #if CWDEBUG_LOCATION && !defined(LIBCWD_CLASS_LOCATION_H)
32 #include <libcwd/class_location.h> // Needed for location_ct.
33 #endif
34 #ifndef LIBCW_CSTDDEF
35 #define LIBCW_CSTDDEF
36 #include <cstddef> // Needed for size_t.
37 #endif
38 #ifndef LIBCWD_SMART_PTR_H
39 #include <libcwd/smart_ptr.h>
40 #endif
41 #ifndef LIBCW_SYS_TIME_H
42 #define LIBCW_SYS_TIME_H
43 #include <sys/time.h> // Needed for struct timeval.
44 #endif
45 
46 namespace libcwd {
47 
48 // Forward declaration
49 class type_info_ct;
50 
51 //===================================================================================================
52 //
53 // The class which describes allocated memory blocks.
54 //
55 
60 class alloc_ct {
61 protected:
62  void const* a_start;
63  size_t a_size;
66  _private_::smart_ptr a_description;
67  struct timeval a_time;
68 #if CWDEBUG_LOCATION
70 #endif
71 
72 public:
76  size_t size() const { return a_size; }
77 
81  void const* start() const { return a_start; }
82 
87 
95  type_info_ct const& type_info() const { return *type_info_ptr; }
96 
102  char const* description() const { return a_description; }
103 
109  struct timeval const& time() const { return a_time; }
110 
111 #if CWDEBUG_LOCATION
112 
119  location_ct const& location() const { return *M_location; }
120 #endif
121 
122 protected:
127  alloc_ct(void const* s, size_t sz, memblk_types_nt type, type_info_ct const& ti, struct timeval const& t
128 #if CWDEBUG_LOCATION
129  , location_ct const* l
130 #endif
131  ) : a_start(s), a_size(sz), a_memblk_type(type), type_info_ptr(&ti), a_time(t)
132 #if CWDEBUG_LOCATION
133  , M_location(l)
134 #endif
135  , M_tagged(false)
136  { }
137 
145  virtual ~alloc_ct() { }
146 
147  // For internal use:
148 private:
149  bool M_tagged; // Set when AllocTag et al was called.
150 public:
151  bool is_tagged() const { return M_tagged; }
152  void alloctag_called() { M_tagged = true; }
153  void reset_type_info() { type_info_ptr = &unknown_type_info_c; }
154 };
155 
156 } // namespace libcwd
157 
158 #endif // LIBCWD_CLASS_ALLOC_H
struct timeval a_time
The time at which the memory was allocated.
Definition: class_alloc.h:67
struct timeval const & time() const
The time at which this allocation was made.
Definition: class_alloc.h:109
size_t size() const
The allocated size in bytes.
Definition: class_alloc.h:76
alloc_ct(void const *s, size_t sz, memblk_types_nt type, type_info_ct const &ti, struct timeval const &t, location_ct const *l)
Construct an alloc_ct object with attributes s, sz, type, ti, t and l.
Definition: class_alloc.h:127
A source file location.
Definition: class_location.h:88
void const * start() const
A pointer to the start of the allocated memory block.
Definition: class_alloc.h:81
char const * description() const
A pointer to a description of the allocated memory block.
Definition: class_alloc.h:102
_private_::smart_ptr a_description
A label describing this memblk.
Definition: class_alloc.h:66
type_info_ct const & type_info() const
A reference to the type info of the pointer to the allocated memory block.
Definition: class_alloc.h:95
type_info_ct const * type_info_ptr
Type info of related object.
Definition: class_alloc.h:65
Class that holds type information for debugging purposes.&#160; Returned by type_info_of().
Definition: type_info.h:44
size_t a_size
Duplicate of (original) memblk_key_ct.
Definition: class_alloc.h:63
An object of type alloc_ct contains information about one allocated memory block. ...
Definition: class_alloc.h:60
memblk_types_nt a_memblk_type
A flag which indicates the type of allocation.
Definition: class_alloc.h:64
memblk_types_nt memblk_type() const
A flag indicating the type of allocation.
Definition: class_alloc.h:86
void const * a_start
Duplicate of (original) memblk_key_ct.
Definition: class_alloc.h:62
namespace for libcwd.
Definition: debug.cc:87
location_ct const & location() const
The source file location that the allocator was called from.
Definition: class_alloc.h:119
location_ct const * M_location
Pointer into the location cache, with the source file, function and line number from where the alloca...
Definition: class_alloc.h:69
virtual ~alloc_ct()
Destructor.
Definition: class_alloc.h:145
memblk_types_nt
A flag indicating the type of allocation.
Definition: enum_memblk_types.h:45
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.