mCRL2
Loading...
Searching...
No Matches
memory_utility.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
18
19#ifndef MCRL2_UTILITIES_DETAIL_MEMORY_UTILITY_H
20#define MCRL2_UTILITIES_DETAIL_MEMORY_UTILITY_H
21
23
24// Reserve a local array of type TYPE and SIZE elements (where SIZE
25// is not necessarily a constant value). These will be allocated on the stack,
26// but the memory will not be initialised, nor will a destructor be called
27// on these memory positions when the reserved data is freed.
28
29#ifdef MCRL2_PLATFORM_WINDOWS
30 #include <malloc.h>
31 #define MCRL2_SPECIFIC_STACK_ALLOCATOR(TYPE, SIZE) reinterpret_cast<TYPE*>(_alloca((SIZE)*sizeof(TYPE)))
32#elif (MCRL2_PLATFORM_LINUX || MCRL2_PLATFORM_MAC)
33 #include <alloca.h>
34 #define MCRL2_SPECIFIC_STACK_ALLOCATOR(TYPE, SIZE) reinterpret_cast<TYPE*>(alloca((SIZE)*sizeof(TYPE)))
35#elif MCRL2_PLATFORM_FREEBSD
36 #include <cstdlib>
37 #define MCRL2_SPECIFIC_STACK_ALLOCATOR(TYPE, SIZE) reinterpret_cast<TYPE*>(alloca((SIZE)*sizeof(TYPE)))
38#else
39 static_assert(false, "MCRL2_SPECIFICATION_STACK_ALLOCATOR has not yet been defined for your platform.");
40#endif
41
42#endif // MCRL2_UTILITIES_DETAIL_MEMORY_UTILITY_H
43