1 /* 2 * The copyright in this software is being made available under the 2-clauses 3 * BSD License, included below. This software may be subject to other third 4 * party and contributor rights, including patent rights, and no such rights 5 * are granted under this license. 6 * 7 * Copyright (c) 2005, Herve Drolon, FreeImage Team 8 * Copyright (c) 2007, Callum Lerwick <seg@haxxed.com> 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 #ifndef OPJ_MALLOC_H 33 #define OPJ_MALLOC_H 34 35 #include <stddef.h> 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 /** 42 @file opj_malloc.h 43 @brief Internal functions 44 45 The functions in opj_malloc.h are internal utilities used for memory management. 46 */ 47 48 /** @defgroup MISC MISC - Miscellaneous internal functions */ 49 /*@{*/ 50 51 /** @name Exported functions */ 52 /*@{*/ 53 /* ----------------------------------------------------------------------- */ 54 55 /** 56 Allocate an uninitialized memory block 57 @param size Bytes to allocate 58 @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available 59 */ 60 void * opj_malloc(size_t size); 61 62 /** 63 Allocate a memory block with elements initialized to 0 64 @param numOfElements Blocks to allocate 65 @param sizeOfElements Bytes per block to allocate 66 @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available 67 */ 68 void * opj_calloc(size_t numOfElements, size_t sizeOfElements); 69 70 /** 71 Allocate memory aligned to a 16 byte boundary 72 @param size Bytes to allocate 73 @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available 74 */ 75 void * opj_aligned_malloc(size_t size); 76 void opj_aligned_free(void* ptr); 77 78 /** 79 Allocate memory aligned to a 32 byte boundary 80 @param size Bytes to allocate 81 @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available 82 */ 83 void * opj_aligned_32_malloc(size_t size); 84 85 /** 86 Reallocate memory blocks. 87 @param m Pointer to previously allocated memory block 88 @param s New size in bytes 89 @return Returns a void pointer to the reallocated (and possibly moved) memory block 90 */ 91 void * opj_realloc(void * m, size_t s); 92 93 /** 94 Deallocates or frees a memory block. 95 @param m Previously allocated memory block to be freed 96 */ 97 void opj_free(void * m); 98 99 #if defined(__GNUC__) && !defined(OPJ_SKIP_POISON) 100 #pragma GCC poison malloc calloc realloc free 101 #endif 102 103 /* ----------------------------------------------------------------------- */ 104 /*@}*/ 105 106 /*@}*/ 107 108 #ifdef __cplusplus 109 } // extern "C" 110 #endif 111 112 #endif /* OPJ_MALLOC_H */ 113