Leviathan  0.8.0.0
Leviathan game engine
Leviathan::OutOfMemoryHandler Class Reference

#include <OutOfMemoryHandler.h>

Public Member Functions

DLLEXPORT OutOfMemoryHandler ()
 
DLLEXPORT ~OutOfMemoryHandler ()
 
DLLEXPORT void HandleException (std::bad_alloc &except)
 

Static Public Member Functions

static DLLEXPORT OutOfMemoryHandlerGet ()
 

Detailed Description

Definition at line 10 of file OutOfMemoryHandler.h.

Constructor & Destructor Documentation

◆ OutOfMemoryHandler()

DLLEXPORT Leviathan::OutOfMemoryHandler::OutOfMemoryHandler ( )

Definition at line 10 of file OutOfMemoryHandler.cpp.

10  {
11  // Allocate memory to use when handling //
12  try{
13  ReservedMemory = new char[OUTOFMEMORY_REQUIREDMEMORY_AMOUNT];
14  }
15  catch (bad_alloc&){
16  // Quite embarrassing, really //
17  exit(321);
18  }
19  // Set static instance //
20  staticinstance = this;
21 }
#define OUTOFMEMORY_REQUIREDMEMORY_AMOUNT

◆ ~OutOfMemoryHandler()

DLLEXPORT Leviathan::OutOfMemoryHandler::~OutOfMemoryHandler ( )

Definition at line 23 of file OutOfMemoryHandler.cpp.

23  {
24  // release allocated memory //
25  delete[] ReservedMemory;
26  ReservedMemory = NULL;
27 }

Member Function Documentation

◆ Get()

DLLEXPORT OutOfMemoryHandler * Leviathan::OutOfMemoryHandler::Get ( )
static

Definition at line 31 of file OutOfMemoryHandler.cpp.

31  {
32  return staticinstance;
33 }

◆ HandleException()

DLLEXPORT void Leviathan::OutOfMemoryHandler::HandleException ( std::bad_alloc &  except)

Definition at line 35 of file OutOfMemoryHandler.cpp.

35  {
36  // release reserved memory //
37  if(ReservedMemory == NULL){
38  // this is rather bad //
39  DEBUG_BREAK;
40  }
41 
42  SAFE_DELETE(ReservedMemory);
43 
44  // we probably now have enough memory to write to log and close and pop up a error window //
45  Logger::Get()->Error("Out of memory! "+string(except.what()));
46  Logger::Get()->Save();
47 
48  // maybe tell engine to try to free up memory //
49 
50  // debug build should never continue out of here
51  DEBUG_BREAK;
52 }
DLLEXPORT void Save()
Definition: Logger.cpp:203
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
#define SAFE_DELETE(x)
Definition: Define.h:147
DLLEXPORT void Error(const std::string &data) override
Definition: Logger.cpp:177

The documentation for this class was generated from the following files: