HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_NoMemHandler.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_NoMemHandler.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  * This class handles memory allocation failures. Currently only
11  * implemented for Windows and Linux.
12  *
13  */
14 #ifndef __UT_NoMemHandler_h__
15 #define __UT_NoMemHandler_h__
16 
17 #include "UT_API.h"
18 #include "UT_NonCopyable.h"
19 #include <stdlib.h>
20 
21 // A UT_NoMemHandlerCallback is a callback that the application can register
22 // if it wants to be notified when memory allocation has failed.
24 
25 // The maximum number of callbacks we allow. We do not need a dynamic
26 // array for these since they should all be registered at code startup.
27 #define UT_MEMHANDLER_MAX_CALLBACKS 16
28 
30 {
31 public:
32  // Global static accessor to UT_NoMemHandler singleton.
33  static UT_NoMemHandler &getNoMemHandler();
34 
35  // Call this method to add a memory handler callback. When memory
36  // allocation fails, these callbacks are called. Their current purpose is
37  // to try to free some memory so that we can save before the inevitable
38  // crash.
39  void addCallback(UT_NoMemHandlerCallback callback);
40 
41  // The main new handlers called by the C-runtime library.
42  int classNewHandler(size_t size);
43 
44  // Disable handler entirely. Used for non-GUI apps like Houdini Engine.
45  void disableHandler();
46 
47 private:
48  // Private constructor/destructor because no one is allowed to allocate us.
50  ~UT_NoMemHandler();
52 
53  // The registered callbacks
55  int myNumCallbacks;
56 
57  // This flag is used to avoid recursive calls into our handler in case
58  // one of the callbacks called from it causes another malloc/new to fail.
59  bool myInsideHandler;
60 
61  // Once disabled, this handler will never allow new callbacks to be added.
62  bool myHandlerDisabled;
63 };
64 
65 #endif
void
Definition: png.h:1083
#define UT_API
Definition: UT_API.h:14
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
void(* UT_NoMemHandlerCallback)()
GLsizeiptr size
Definition: glcorearb.h:664
#define UT_MEMHANDLER_MAX_CALLBACKS