File: memory.cc

package info (click to toggle)
asymptote 3.05%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,420 kB
  • sloc: cpp: 172,663; ansic: 69,690; python: 14,957; sh: 5,605; javascript: 4,871; lisp: 1,507; perl: 1,417; makefile: 1,026; yacc: 610; lex: 449; xml: 182; asm: 8
file content (74 lines) | stat: -rw-r--r-- 1,123 bytes parent folder | download | duplicates (2)
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