// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
#include <Standard_MMgrOpt.hxx>
#include <Standard_OutOfMemory.hxx>
#include <Standard_Assert.hxx>
#include <stdio.h>
+#include <errno.h>
-#ifdef _WIN32
-# include <windows.h>
-#else
+#ifndef _WIN32
# include <sys/mman.h> /* mmap() */
#endif
extern "C" int getpagesize() ;
#endif
+#ifdef _WIN32
+#include <strsafe.h>
+#endif
//======================================================================
// Assumptions
//======================================================================
#define GET_USER(block) (((Standard_Size*)(block)) + BLOCK_SHIFT)
#define GET_BLOCK(storage) (((Standard_Size*)(storage))-BLOCK_SHIFT)
-// create static instance of out-of-memory exception to protect
-// against possible lack of memory for its raising
-static Handle(Standard_OutOfMemory) anOutOfMemError = new Standard_OutOfMemory;
-
//=======================================================================
//function : Standard_MMgr
//purpose :
perror("ERR_MEMRY_FAIL");
#endif
-#if defined(IRIX) || defined(__sgi) || defined(SOLARIS) || defined(__sun) || defined(__linux__) || defined(linux) || defined(__FreeBSD__) || defined(__ANDROID__)
+#if defined(IRIX) || defined(__sgi) || defined(SOLARIS) || defined(__sun) || defined(__linux__) || defined(__FreeBSD__) || defined(__ANDROID__)
if ((myMMap = open ("/dev/zero", O_RDWR)) < 0) {
if ((myMMap = open ("/dev/null", O_RDWR)) < 0){
myMMap = 0;
aBlock = (Standard_Size*)calloc(RoundSizeN+BLOCK_SHIFT, sizeof(Standard_Size));
// if still not succeeded, raise exception
if ( ! aBlock )
- anOutOfMemError->Reraise ("Standard_MMgrOpt::Allocate(): malloc failed");
+ throw Standard_OutOfMemory("Standard_MMgrOpt::Allocate(): malloc failed");
}
// initialize new block header by its size
if ( Purge(Standard_False) )
goto retry;
// if nothing helps, raise exception
- anOutOfMemError->Reraise (strerror(errcode));
+ throw Standard_OutOfMemory(strerror(errcode));
}
// save actually allocated size into argument
goto retry;
// if nothing helps, make error message and raise exception
const int BUFSIZE=1024;
- char message[BUFSIZE];
- if ( FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), 0, message, BUFSIZE-1, 0) <=0 )
- strcpy (message, "Standard_MMgrOpt::AllocMemory() failed to mmap");
- anOutOfMemError->Reraise (message);
+
+ wchar_t message[BUFSIZE];
+
+ if ( FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), 0,
+ message, BUFSIZE-1, 0) <=0 )
+ StringCchCopyW(message, _countof(message), L"Standard_MMgrOpt::AllocMemory() failed to mmap");
+
+ char messageA[BUFSIZE];
+ WideCharToMultiByte(CP_UTF8, 0, message, -1, messageA, sizeof(messageA), NULL, NULL);
+ throw Standard_OutOfMemory(messageA);
}
// record map handle in the beginning
if ( Purge(Standard_False) )
goto retry;
// if nothing helps, raise exception
- anOutOfMemError->Reraise ("Standard_MMgrOpt::Allocate(): malloc failed");
+ throw Standard_OutOfMemory("Standard_MMgrOpt::Allocate(): malloc failed");
}
}
// clear whole block if clearing option is set