memory_allocations.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2016 The Earlham Institute
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 
24 #ifndef MEMORY_ALLOCATIONS_H
25 #define MEMORY_ALLOCATIONS_H
26 
27 #include "typedefs.h"
28 
36 typedef enum MEM_FLAG
37 {
40 
43 
46 
49 } MEM_FLAG;
50 
51 
52 #ifdef __cplusplus
53  extern "C" {
54 #endif
55 
56 
57 #ifdef AMIGA
58  #include "amiga_platform.h"
59  #define InitAllocator() InitAmigaAllocator()
60  #define ExitAllocator() ExitAmigaAllocator()
61  #define AllocMemory(x) AllocateAmigaMemory(x)
62  #define AllocMemoryArray(x,y) AllocateAmigaZeroedArray(x,y)
63  #define ReallocMemory(x,y,z) ReallocateAmigaMemory(x,y,z)
64  #define FreeMemory(x) FreeAmigaMemory(x)
65  #define IsAllocatorThreadSafe() IsAmigaAllocatorThreadSafe()
66 #else
67 
68  #ifdef WIN32
69  // #define USE_NEDMALLOC_ALLOCATOR
70  #elif defined UNIX
71 
72  #endif
73 
74  #ifdef USE_TLSF_ALLOCATOR
75  #elif defined USE_NEDMALLOC_ALLOCATOR
76  #include "nedmalloc_allocator.h"
77  #define InitAllocator() InitNedmallocAllocator()
78  #define ExitAllocator() ExitNedmallocAllocator()
79  #define AllocMemory(x) AllocateNedmallocMemory(x)
80  #define AllocMemoryArray(x,y) AllocateNedmallocZeroedArray(x,y)
81  #define ReallocMemory(x,y,z) ReallocateNedmallocMemory(x,y,z)
82  #define FreeMemory(x) FreeNedmallocMemory(x)
83  #define IsAllocatorThreadSafe() IsNedmallocAllocatorThreadSafe()
84  #else
85  #if defined _DEBUG && defined _MSC_VER
86  #define _CRTDBG_MAP_ALLOC
87  #include <stdlib.h>
88  #include <crtdbg.h>
89  #else
90  #include <stdlib.h>
91  #endif
92 
94  #define InitAllocator() do {} while (0);
95 
97  #define ExitAllocator() do {} while (0);
98 
102  #define AllocMemory(x) malloc(x)
103 
104 
110  #define AllocMemoryArray(x,y) calloc(x,y)
111 
115  #define ReallocMemory(x,y,z) realloc(x,y)
116 
118  #define FreeMemory(x) free(x)
119 
121  #define IsAllocatorThreadSafe() (1)
122  #endif
123 
124 #endif
125 
126 
127 
141 int AllocateSharedMemory (const char *id_s, size_t size, int flags);
142 
143 
153 bool FreeSharedMemory (int id);
154 
155 
165 void *OpenSharedMemory (int id, int flags);
166 
167 
177 bool CloseSharedMemory (void *value_p);
178 
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 
184 #endif /* #ifndef MEMORY_ALLOCATIONS_H */
MEM_FLAG
An enum specifying the particular status of a piece of dynamically allocated memory for a particular ...
Definition: memory_allocations.h:36
int AllocateSharedMemory(const char *id_s, size_t size, int flags)
Allocate some memory that can shared between different processes.
bool CloseSharedMemory(void *value_p)
Close a shared memory segment.
Make a separate copy of the object pointed at by the source pointer.
Definition: memory_allocations.h:42
Use the pointer value.
Definition: memory_allocations.h:48
Use the pointer value.
Definition: memory_allocations.h:45
void * OpenSharedMemory(int id, int flags)
Open a shared memory segment.
The memory has already been freed so no action need be taken.
Definition: memory_allocations.h:39
bool FreeSharedMemory(int id)
Free the shared memory segment for a given id.
None of these functions should be called directly, they will be set up by the generated system and al...