blob: 9407fbd57312df56232f5ce458e8d9ce2846d478 (
plain)
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
|
// file : xsde/cxx/allocator.hxx
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
#ifndef XSDE_CXX_ALLOCATOR_HXX
#define XSDE_CXX_ALLOCATOR_HXX
#include <stddef.h> // size_t
#include <new> // placement new
#include <xsde/cxx/config.hxx>
namespace xsde
{
namespace cxx
{
// Allocate a memory block using custom allocator. If exceptions
// are enabled this function throws std::bad_alloc on failure.
// Otherwise it returns 0.
//
void*
alloc (size_t);
void
free (void*);
#ifdef XSDE_EXCEPTIONS
struct alloc_guard
{
alloc_guard (void* p) : p_ (p) {}
~alloc_guard () { if (p_) cxx::free (p_); }
void*
get () const { return p_; }
void
release () { p_ = 0; }
private:
void* p_;
};
#endif
}
}
#include <xsde/cxx/allocator.ixx>
#endif // XSDE_CXX_ALLOCATOR_HXX
|