v0.3.0
Fast, portable C library for geometry input/output
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Modules
memblock.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (c) 2016, Fougue Ltd. <http://www.fougue.pro>
3 ** All rights reserved.
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
7 ** are met:
8 **
9 ** 1. Redistributions of source code must retain the above copyright
10 ** notice, this list of conditions and the following disclaimer.
11 **
12 ** 2. Redistributions in binary form must reproduce the above
13 ** copyright notice, this list of conditions and the following
14 ** disclaimer in the documentation and/or other materials provided
15 ** with the distribution.
16 **
17 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ****************************************************************************/
29 
37 #ifndef GMIO_MEMBLOCK_H
38 #define GMIO_MEMBLOCK_H
39 
40 #include "global.h"
41 
42 #include <stddef.h>
43 
60 {
62  void* ptr;
63 
65  size_t size;
66 
72  void (*func_deallocate)(void* ptr);
73 };
74 
76 
78 GMIO_API bool gmio_memblock_isnull(const struct gmio_memblock* mblock);
79 
85  void* ptr, size_t size, void (*func_deallocate)(void*));
86 
91 GMIO_API struct gmio_memblock gmio_memblock_malloc(size_t size);
92 
97 GMIO_API struct gmio_memblock gmio_memblock_calloc(size_t num, size_t size);
98 
103 GMIO_API struct gmio_memblock gmio_memblock_realloc(void* ptr, size_t size);
104 
106 GMIO_API void gmio_memblock_deallocate(struct gmio_memblock* mblock);
107 
113 typedef struct gmio_memblock (*gmio_memblock_constructor_func_t)();
114 
124 
130 
133 GMIO_API struct gmio_memblock gmio_memblock_default();
134 
136 
137 #endif /* GMIO_MEMBLOCK_H */
138 
struct gmio_memblock gmio_memblock_default()
Returns a gmio_memblock object created using the function gmio_memblock_default_constructor() ...
struct gmio_memblock gmio_memblock_realloc(void *ptr, size_t size)
Returns a gmio_memblock object allocated with standard realloc()
#define GMIO_API
Expands either to GMIO_DECL_EXPORT or GMIO_DECL_IMPORT when respectively compiling/using the DLL...
Definition: global.h:90
Fundamental global declarations, included by almost all other header/source files.
void(* func_deallocate)(void *ptr)
Optional pointer on a function that deallocates the memory block beginning at ptr.
Definition: memblock.h:72
#define GMIO_C_LINKAGE_BEGIN
Expands to extern "C" { when building with a C++ compiler.
Definition: global.h:195
struct gmio_memblock(* gmio_memblock_constructor_func_t)()
Typedef for a pointer to a function that creates an allocated mblock.
Definition: memblock.h:113
struct gmio_memblock gmio_memblock_malloc(size_t size)
Returns a gmio_memblock object allocated with standard malloc()
void gmio_memblock_deallocate(struct gmio_memblock *mblock)
Safe and convenient call to gmio_memblock::func_deallocate()
void gmio_memblock_set_default_constructor(gmio_memblock_constructor_func_t ctor)
Installs a global function to construct gmio_memblock objects.
#define GMIO_C_LINKAGE_END
Expands to } when building with a C++ compiler.
Definition: global.h:197
struct gmio_memblock gmio_memblock_calloc(size_t num, size_t size)
Returns a gmio_memblock object allocated with standard calloc()
void * ptr
Pointer to the beginning of the memory block.
Definition: memblock.h:62
gmio_memblock_constructor_func_t gmio_memblock_default_constructor()
Returns the currently installed function to construct gmio_memblock objects.
size_t size
Size (in bytes) of the memory block.
Definition: memblock.h:65
Basic memory block.
Definition: memblock.h:59
bool gmio_memblock_isnull(const struct gmio_memblock *mblock)
Returns true if mblock is NULL or points to null/void memory.
Fougue © 2016