v0.4.1
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) 2017, 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 #pragma once
38 
39 #include "global.h"
40 #include <stddef.h>
41 
58 {
60  void* ptr;
61 
63  size_t size;
64 
67  void (*func_deallocate)(void* ptr);
68 };
69 
71 
73 GMIO_API bool gmio_memblock_isnull(const struct gmio_memblock* mblock);
74 
78  void* ptr, size_t size, void (*func_deallocate)(void*));
79 
82 GMIO_API struct gmio_memblock gmio_memblock_malloc(size_t size);
83 
86 GMIO_API struct gmio_memblock gmio_memblock_calloc(size_t num, size_t size);
87 
90 GMIO_API struct gmio_memblock gmio_memblock_realloc(void* ptr, size_t size);
91 
93 GMIO_API void gmio_memblock_deallocate(struct gmio_memblock* mblock);
94 
99 typedef struct gmio_memblock (*gmio_memblock_constructor_func_t)();
100 
109 
113 
116 GMIO_API struct gmio_memblock gmio_memblock_default();
117 
119 
struct gmio_memblock gmio_memblock_default()
Returns a memblock created with the function gmio_memblock_default_constructor()
struct gmio_memblock gmio_memblock_realloc(void *ptr, size_t size)
Returns a memblock 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:89
Fundamental global declarations, included by almost all other header/source files.
void(* func_deallocate)(void *ptr)
Optional function that deallocates the memory block beginning at ptr.
Definition: memblock.h:67
#define GMIO_C_LINKAGE_BEGIN
Expands to extern "C" { when building with a C++ compiler.
Definition: global.h:203
struct gmio_memblock(* gmio_memblock_constructor_func_t)()
Typedef for a pointer to a function that creates an allocated memblock.
Definition: memblock.h:99
struct gmio_memblock gmio_memblock_malloc(size_t size)
Returns a memblock 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:205
struct gmio_memblock gmio_memblock_calloc(size_t num, size_t size)
Returns a memblock allocated with standard calloc().
void * ptr
Pointer to the beginning of the memory block.
Definition: memblock.h:60
gmio_memblock_constructor_func_t gmio_memblock_default_constructor()
Returns the currently installed function to construct memblock objects.
size_t size
Size (in bytes) of the memory block.
Definition: memblock.h:63
Basic memory block.
Definition: memblock.h:57
bool gmio_memblock_isnull(const struct gmio_memblock *mblock)
Returns true if mblock is NULL or points to null/void memory.
Fougue © 2017