HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 <stdlib.h>
19 
20 // A UT_NoMemHandlerCallback is a callback that the application can register
21 // if it wants to be notified when memory allocation has failed.
23 
24 // The maximum number of callbacks we allow. We do not need a dynamic
25 // array for these since they should all be registered at code startup.
26 #define UT_MEMHANDLER_MAX_CALLBACKS 16
27 
29 {
30 public:
31  // Global static accessor to UT_NoMemHandler singleton.
32  static UT_NoMemHandler &getNoMemHandler();
33 
34  // Call this method to add a memory handler callback. When memory
35  // allocation fails, these callbacks are called. Their current purpose is
36  // to try to free some memory so that we can save before the inevitable
37  // crash.
38  void addCallback(UT_NoMemHandlerCallback callback);
39 
40  // The main new handlers called by the C-runtime library.
41  int classNewHandler(size_t size);
42 
43  // Disable handler entirely. Used for non-GUI apps like Houdini Engine.
44  void disableHandler();
45 
46 private:
47  // Private constructor/destructor because no one is allowed to allocate us.
49  ~UT_NoMemHandler();
50 
51 
52  // The registered callbacks
54  int myNumCallbacks;
55 
56  // This flag is used to avoid recursive calls into our handler in case
57  // one of the callbacks called from it causes another malloc/new to fail.
58  bool myInsideHandler;
59 
60  // Once disabled, this handler will never allow new callbacks to be added.
61  bool myHandlerDisabled;
62 };
63 
64 #endif
void(* UT_NoMemHandlerCallback)(void)
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
#define UT_API
Definition: UT_API.h:12
GLsizeiptr size
Definition: glcorearb.h:663
#define UT_MEMHANDLER_MAX_CALLBACKS