Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
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"
29 
30 
38 typedef enum MEM_FLAG
39 {
42 
45 
48 
51 } MEM_FLAG;
52 
53 
54 #ifdef __cplusplus
55  extern "C" {
56 #endif
57 
58 
59 #ifdef AMIGA
60  #include "amiga_platform.h"
61  #define InitAllocator() InitAmigaAllocator()
62  #define ExitAllocator() ExitAmigaAllocator()
63  #define AllocMemory(x) AllocateAmigaMemory(x)
64  #define AllocMemoryArray(x,y) AllocateAmigaZeroedArray(x,y)
65  #define ReallocMemory(x,y,z) ReallocateAmigaMemory(x,y,z)
66  #define FreeMemory(x) FreeAmigaMemory(x)
67  #define IsAllocatorThreadSafe() IsAmigaAllocatorThreadSafe()
68 #else
69 
70  #ifdef WINDOWS
71  // #define USE_NEDMALLOC_ALLOCATOR
72  #elif defined UNIX
73 
74  #endif
75 
76  #ifdef USE_TLSF_ALLOCATOR
77  #elif defined USE_NEDMALLOC_ALLOCATOR
78  #include "nedmalloc_allocator.h"
79  #define InitAllocator() InitNedmallocAllocator()
80  #define ExitAllocator() ExitNedmallocAllocator()
81  #define AllocMemory(x) AllocateNedmallocMemory(x)
82  #define AllocMemoryArray(x,y) AllocateNedmallocZeroedArray(x,y)
83  #define ReallocMemory(x,y,z) ReallocateNedmallocMemory(x,y,z)
84  #define FreeMemory(x) FreeNedmallocMemory(x)
85  #define IsAllocatorThreadSafe() IsNedmallocAllocatorThreadSafe()
86  #else
87  #if defined _DEBUG && defined _MSC_VER
88  //#undef _CRTDBG_MAP_ALLOC
89  #include <stdlib.h>
90  #include <crtdbg.h>
91  #else
92  #include <stdlib.h>
93  #endif
94 
96  #define InitAllocator() do {} while (0);
97 
99  #define ExitAllocator() do {} while (0);
100 
104  #define AllocMemory(x) malloc(x)
105 
106 
112  #define AllocMemoryArray(x,y) calloc(x,y)
113 
117  #define ReallocMemory(x,y,z) realloc(x,y)
118 
120  #define FreeMemory(x) free(x)
121 
123  #define IsAllocatorThreadSafe() (1)
124  #endif
125 
126 #endif
127 
128 
129 struct MappedMemory;
130 
131 
145 GRASSROOTS_UTIL_API struct MappedMemory *AllocateSharedMemory (const char *id_s, size_t size, int flags);
146 
147 
157 GRASSROOTS_UTIL_API bool FreeSharedMemory (struct MappedMemory *mapped_memory_p);
158 
159 
169 GRASSROOTS_UTIL_API void *OpenSharedMemory (struct MappedMemory *mapped_memory_p, int flags);
170 
171 
181 GRASSROOTS_UTIL_API bool CloseSharedMemory (struct MappedMemory *mapped_memory_p, void *value_p);
182 
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 
188 #endif /* #ifndef MEMORY_ALLOCATIONS_H */
MF_ALREADY_FREED
The memory has already been freed so no action need be taken.
Definition: memory_allocations.h:41
MF_DEEP_COPY
Make a separate copy of the object pointed at by the source pointer.
Definition: memory_allocations.h:44
MEM_FLAG
MEM_FLAG
An enum specifying the particular status of a piece of dynamically allocated memory for a particular ...
Definition: memory_allocations.h:38
grassroots_util_library.h
MF_SHALLOW_COPY
Use the pointer value.
Definition: memory_allocations.h:47
typedefs.h
amiga_platform.h
None of these functions should be called directly, they will be set up by the generated system and al...
CloseSharedMemory
bool CloseSharedMemory(struct MappedMemory *mapped_memory_p, void *value_p)
Close a shared memory segment.
OpenSharedMemory
void * OpenSharedMemory(struct MappedMemory *mapped_memory_p, int flags)
Open a shared memory segment.
MF_SHADOW_USE
Use the pointer value.
Definition: memory_allocations.h:50
FreeSharedMemory
bool FreeSharedMemory(struct MappedMemory *mapped_memory_p)
Free the shared memory segment for a given id.
GRASSROOTS_UTIL_API
#define GRASSROOTS_UTIL_API
Definition: grassroots_util_library.h:47
AllocateSharedMemory
struct MappedMemory * AllocateSharedMemory(const char *id_s, size_t size, int flags)
Allocate some memory that can shared between different processes.