opennurbs_memory.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_MEMORY_INC_)
18 #define OPENNURBS_MEMORY_INC_
19 
20 #if defined (cplusplus) || defined(_cplusplus) || defined(__cplusplus)
21 extern "C" {
22 #endif
23 
24 ON_DECL
25 size_t ON_MemoryPageSize();
26 
27 
28 /*
29 Allocate memory that is intentionally never returned
30 should not be considered a memory leak. Typically this is
31 for an application workspace.
32 */
33 ON_DECL
34 void* onmalloc_forever( size_t );
35 
36 ON_DECL
37 void* onmalloc( size_t );
38 
39 ON_DECL
40 void* oncalloc( size_t, size_t );
41 
42 ON_DECL
43 void onfree( void* );
44 
45 ON_DECL
46 void* onrealloc( void*, size_t );
47 
48 ON_DECL
49 void* onmemdup( const void*, size_t );
50 
51 ON_DECL
52 char* onstrdup( const char* );
53 
54 ON_DECL
55 wchar_t* onwcsdup( const wchar_t* );
56 
57 ON_DECL
58 unsigned char* onmbsdup( const unsigned char* );
59 
60 #if defined (cplusplus) || defined(_cplusplus) || defined(__cplusplus)
61 }
62 
63 class ON_CLASS ON_MemoryAllocationTracking
64 {
65 public:
66  /*
67  Descrption:
68  Windows Debug Builds:
69  The constructor saves the current state of memory allocation tracking
70  and then enables/disables memory allocation tracking.
71  Otherwise:
72  Does nothting.
73  */
74  ON_MemoryAllocationTracking(
75  bool bEnableAllocationTracking
76  );
77 
78  /*
79  Descrption:
80  Windows Debug Builds:
81  The desctructor restores the saved state of memory allocation tracking.
82  Otherwise:
83  Does nothting.
84  */
85  ~ON_MemoryAllocationTracking();
86 
87 private:
88  static unsigned int m_g_stack_depth;
89  static int m_g_crt_dbg_flag0;
90  const unsigned int m_this_statck_depth;
91  const int m_this_crt_dbg_flag0;
92 
93 private:
94  ON_MemoryAllocationTracking() = delete;
95  ON_MemoryAllocationTracking(const ON_MemoryAllocationTracking&) = delete;
96  ON_MemoryAllocationTracking& operator=(const ON_MemoryAllocationTracking&) = delete;
97 };
98 
99 #endif
100 
101 #endif