plibsys  0.0.4
pmem.h
Go to the documentation of this file.
1 /*
2  * The MIT License
3  *
4  * Copyright (C) 2010-2017 Alexander Saprykin <saprykin.spb@gmail.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * 'Software'), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
67 #if !defined (PLIBSYS_H_INSIDE) && !defined (PLIBSYS_COMPILATION)
68 # error "Header files shouldn't be included directly, consider using <plibsys.h> instead."
69 #endif
70 
71 #ifndef PLIBSYS_HEADER_PMEM_H
72 #define PLIBSYS_HEADER_PMEM_H
73 
74 #include <ptypes.h>
75 #include <pmacros.h>
76 #include <perror.h>
77 
79 
81 typedef struct PMemVTable_ {
82  ppointer (*malloc) (psize n_bytes);
84  psize n_bytes);
85  void (*free) (ppointer mem);
86 } PMemVTable;
87 
96 
106 
116  psize n_bytes);
117 
129 P_LIB_API void p_free (ppointer mem);
130 
146 
154 P_LIB_API void p_mem_restore_vtable (void);
155 
174  PError **error);
175 
186  psize n_bytes,
187  PError **error);
188 
190 
191 #endif /* PLIBSYS_HEADER_PMEM_H */
#define P_END_DECLS
Closes .h file declarations to be exported as C functions, should be always used after P_BEGIN_DECLS...
Definition: pmacros.h:299
struct PMemVTable_ PMemVTable
Memory management table.
P_LIB_API pboolean p_mem_set_vtable(const PMemVTable *table)
Sets custom memory management routines.
P_LIB_API ppointer p_malloc0(psize n_bytes)
Allocates a memory block for the specified number of bytes and fills it with zeros.
Memory management table.
Definition: pmem.h:81
P_LIB_API ppointer p_malloc(psize n_bytes)
Allocates a memory block for the specified number of bytes.
struct PError_ PError
Opaque data structure for an error object.
Definition: perror.h:68
unsigned __int64 psize
Type for a platform independent size_t.
Definition: ptypes.h:194
Miscellaneous macros.
void * ppointer
Type for a pointer.
Definition: ptypes.h:109
signed int pboolean
Type for a bool.
Definition: ptypes.h:114
P_LIB_API ppointer p_mem_mmap(psize n_bytes, PError **error)
Gets a memory mapped block from the system.
ppointer(* malloc)(psize n_bytes)
malloc() implementation.
Definition: pmem.h:82
Error report system.
P_LIB_API pboolean p_mem_munmap(ppointer mem, psize n_bytes, PError **error)
Unmaps memory back to the system.
P_LIB_API void p_free(ppointer mem)
Frees a memory block by its pointer.
P_LIB_API void p_mem_restore_vtable(void)
Restores system memory management routines.
P_LIB_API ppointer p_realloc(ppointer mem, psize n_bytes)
Changes the memory block size.
#define P_LIB_API
Exports a symbol from a shared library.
Definition: pmacros.h:138
Types definitions.
void(* free)(ppointer mem)
free() implementation.
Definition: pmem.h:85
ppointer(* realloc)(ppointer mem, psize n_bytes)
realloc() implementation.
Definition: pmem.h:83
#define P_BEGIN_DECLS
Starts .h file declarations to be exported as C functions.
Definition: pmacros.h:298