1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
/**
* @file memory.cc
* @brief Implementation of certain gc-related functions
*/
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#include "memory.h"
#include <memory>
// asy_malloc functions + GC_throw_bad_alloc
#if defined(USEGC)
void* asy_malloc(size_t n)
{
#ifdef GC_DEBUG
if(void *mem=GC_debug_malloc_ignore_off_page(n, GC_EXTRAS))
#else
if(void *mem=GC_malloc_ignore_off_page(n))
#endif
return mem;
throw std::bad_alloc();
}
void* asy_malloc_atomic(size_t n)
{
#ifdef GC_DEBUG
if(void *mem=GC_debug_malloc_atomic_ignore_off_page(n, GC_EXTRAS))
#else
if(void *mem=GC_malloc_atomic_ignore_off_page(n))
#endif
return mem;
throw std::bad_alloc();
}
#if !defined(_WIN32)
GC_API void GC_CALL GC_throw_bad_alloc()
{
throw std::bad_alloc();
}
#endif
#endif // defined(USEGC)
// compact & stdString functions
namespace mem
{
#if defined(USEGC)
void compact(int x)
{
GC_set_dont_expand(x);
}
std::string stdString(string s)
{
return std::string(s.c_str());
}
#else // defined(USEGC)
std::string stdString(string s)
{
return s;
}
#endif // defined(USEGC)
}
// throw bad alloc
|