FastUIDraw
fastuidraw_memory.hpp
Go to the documentation of this file.
1 /*!
2  * \file fastuidraw_memory.hpp
3  * \brief file fastuidraw_memory.hpp
4  *
5  * Adapted from: WRATHNew.hpp and WRATHmemory.hpp of WRATH:
6  *
7  * Copyright 2013 by Nomovok Ltd.
8  * Contact: info@nomovok.com
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@nomovok.com>
16  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
17  *
18  */
19 
20 #ifndef FASTUIDRAW_FASTUIDRAW_MEMORY_HPP
21 #define FASTUIDRAW_FASTUIDRAW_MEMORY_HPP
22 
23 /*!\addtogroup Utility
24  * @{
25  */
26 
27 #include <cstdlib>
29 
30 /*!\def FASTUIDRAWnew
31  * When creating FastUIDraw objects, one must use FASTUIDRAWnew instead of new
32  * to create objects. For debug build of FastUIDraw, allocations with FASTUIDRAWnew
33  * are tracked and at program exit a list of those objects not deleted by
34  * FASTUIDRAWdelete are printed with the file and line number of the allocation.
35  * For release builds of FastUIDraw, allocations are not tracked and std::malloc
36  * is used to allocate memory. Do NOT use FASTUIDRAWnew for creating arrays
37  * (i.e. p = new type[N]) as FASTUIDRAWdelete does not handle array deletion.
38  */
39 #define FASTUIDRAWnew \
40  ::new(__FILE__, __LINE__)
41 
42 /*!\def FASTUIDRAWdelete
43  * Use \ref FASTUIDRAWdelete to delete objects that were allocated with \ref
44  * FASTUIDRAWnew. For debug builds of FastUIDraw, if the memory was not tracked
45  * an error message is emitted.
46  * \param ptr address of object to delete, value must be a return value
47  * from FASTUIDRAWnew
48  */
49 #define FASTUIDRAWdelete(ptr) \
50  do { \
51  fastuidraw::memory::check_object_exists(ptr, __FILE__, __LINE__); \
52  fastuidraw::memory::call_dtor(ptr); \
53  fastuidraw::memory::free_implement(ptr, __FILE__, __LINE__); \
54  } while(0)
55 
56 /*!\def FASTUIDRAWmalloc
57  * For debug build of FastUIDraw, allocations with \ref FASTUIDRAWmalloc are tracked and
58  * at program exit a list of those objects not deleted by \ref FASTUIDRAWfree
59  * are printed with the file and line number of the allocation. For release builds
60  * of FastUIDraw, maps to std::malloc.
61  */
62 #define FASTUIDRAWmalloc(size) \
63  fastuidraw::memory::malloc_implement(size, __FILE__, __LINE__)
64 
65 /*!\def FASTUIDRAWcalloc
66  * For debug build of FastUIDraw, allocations with \ref FASTUIDRAWcalloc are tracked and
67  * at program exit a list of those objects not deleted by \ref FASTUIDRAWfree
68  * are printed with the file and line number of the allocation. For release builds
69  * of FastUIDraw, maps to std::calloc.
70  * \param nmemb number of elements to allocate
71  * \param size size of each element in bytes
72  */
73 #define FASTUIDRAWcalloc(nmemb, size) \
74  fastuidraw::memory::calloc_implement(nmemb, size, __FILE__, __LINE__)
75 
76 /*!\def FASTUIDRAWrealloc
77  * For debug build of FastUIDraw, allocations with \ref FASTUIDRAWrealloc are tracked and
78  * at program exit a list of those objects not deleted by \ref FASTUIDRAWfree
79  * are printed with the file and line number of the allocation. For release builds
80  * of FastUIDraw, maps to std::realloc.
81  * \param ptr pointer at which to rellocate
82  * \param size new size
83  */
84 #define FASTUIDRAWrealloc(ptr, size) \
85  fastuidraw::memory::realloc_implement(ptr, size, __FILE__, __LINE__)
86 
87 /*!\def FASTUIDRAWfree
88  * Use FASTUIDRAWfree for objects allocated with FASTUIDRAWmalloc,
89  * FASTUIDRAWrealloc and FASTUIDRAWcalloc. For release builds of
90  * FastUIDraw, maps to std::free.
91  * \param ptr address of object to free
92  */
93 #define FASTUIDRAWfree(ptr) \
94  fastuidraw::memory::free_implement(ptr, __FILE__, __LINE__)
95 
96 /*! @} */
97 
98 #endif
file fastuidraw_memory_private.hpp