v0.1.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 ** gmio
3 ** Copyright Fougue (24 Jun. 2016)
4 ** contact@fougue.pro
5 **
6 ** This software is a reusable library whose purpose is to provide complete
7 ** I/O support for various CAD file formats (eg. STL)
8 **
9 ** This software is governed by the CeCILL-B license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-B
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
14 ****************************************************************************/
15 
23 #ifndef GMIO_MEMBLOCK_H
24 #define GMIO_MEMBLOCK_H
25 
26 #include "global.h"
27 
28 #include <stddef.h>
29 
46 {
48  void* ptr;
49 
51  size_t size;
52 
58  void (*func_deallocate)(void* ptr);
59 };
60 
62 
64 GMIO_API bool gmio_memblock_isnull(const struct gmio_memblock* mblock);
65 
71  void* ptr, size_t size, void (*func_deallocate)(void*));
72 
77 GMIO_API struct gmio_memblock gmio_memblock_malloc(size_t size);
78 
83 GMIO_API struct gmio_memblock gmio_memblock_calloc(size_t num, size_t size);
84 
89 GMIO_API struct gmio_memblock gmio_memblock_realloc(void* ptr, size_t size);
90 
92 GMIO_API void gmio_memblock_deallocate(struct gmio_memblock* mblock);
93 
99 typedef struct gmio_memblock (*gmio_memblock_constructor_func_t)();
100 
110 
116 
119 GMIO_API struct gmio_memblock gmio_memblock_default();
120 
122 
123 #endif /* GMIO_MEMBLOCK_H */
124 
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:76
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:58
#define GMIO_C_LINKAGE_BEGIN
Expands to extern "C" { when building with a C++ compiler.
Definition: global.h:181
struct gmio_memblock(* gmio_memblock_constructor_func_t)()
Typedef for a pointer to a function that creates an allocated mblock.
Definition: memblock.h:99
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:183
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:48
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:51
Basic memory block.
Definition: memblock.h:45
bool gmio_memblock_isnull(const struct gmio_memblock *mblock)
Returns true if mblock is NULL or points to null/void memory.
Fougue © 2016