/* $Id: cpl_xmemory.c,v 1.24 2007/12/21 13:17:23 llundin Exp $ * * This file is part of the ESO Common Pipeline Library * Copyright (C) 2001-2004 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * $Author: llundin $ * $Date: 2007/12/21 13:17:23 $ * $Revision: 1.24 $ * $Name: $ */ #ifdef HAVE_CONFIG_H #include #endif /*----------------------------------------------------------------------------- Includes -----------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #include #include "cpl_xmemory.h" /*----------------------------------------------------------------------------- Defines -----------------------------------------------------------------------------*/ #ifndef inline #define inline /* inline */ #endif #define CPL_XSTRINGIFY(TOSTRING) #TOSTRING #define CPL_STRINGIFY(TOSTRING) CPL_XSTRINGIFY(TOSTRING) /* This symbol defines the level of usage of the memory module. 0 Use the memory system calls. 1 Use the memory system calls, but exit if they are not succesfull 2 Fully use the memory functions */ /* Initial number of entries in memory table */ /* If this number is big, the size of the memory table can become problematic. */ /* Use a prime number to reduce risk of hashing clashes */ #ifndef CPL_XMEMORY_MAXPTRS #error "CPL_XMEMORY_MAXPTRS is not defined" #endif #if CPL_XMEMORY_MAXPTRS <= 0 #error "CPL_XMEMORY_MAXPTRS must be positive" #endif #ifndef CPL_XMEMORY_RESIZE_THRESHOLD #define CPL_XMEMORY_RESIZE_THRESHOLD 0.9 #endif #ifndef CPL_XMEMORY_RESIZE_FACTOR #define CPL_XMEMORY_RESIZE_FACTOR 2 #endif /*----------------------------------------------------------------------------- Macros -----------------------------------------------------------------------------*/ /* A very simple hash */ #define PTR_HASH(ptr) \ ((unsigned)(((unsigned long) ptr) % cpl_xmemory_table_size)) #define CPL_XMEMORY_TYPE_FREE 0 #define CPL_XMEMORY_TYPE_MALLOC 1 #define CPL_XMEMORY_TYPE_CALLOC 2 #define CPL_XMEMORY_TYPE_REALLOC 3 /*----------------------------------------------------------------------------- Private variables -----------------------------------------------------------------------------*/ static const char * cpl_xmemory_type[] = {"free", "malloc", "calloc", "realloc"}; /* Initialization flag */ static int cpl_xmemory_initialized = 0; /* Number of active cells */ static unsigned cpl_xmemory_ncells = 0; /* Peak number of pointers ever seen for diagnostics */ static unsigned cpl_xmemory_max_cells = 0; /* Total allocated RAM in bytes */ static size_t cpl_xmemory_alloc_ram = 0; /* Peak allocation ever seen for diagnostics */ static size_t cpl_xmemory_alloc_max = 0; /* The current size of the xmemory table */ static size_t cpl_xmemory_table_size = 0; /* The default size of the xmemory table, when it is non-empty */ static size_t cpl_xmemory_table_size_max = 0; /* Various infos about the pointers */ /* List of pointers */ static const void ** cpl_xmemory_p_val; /* Type of allocation */ /* - CPL_XMEMORY_TYPE_FREE means no allocation */ static unsigned char * cpl_xmemory_p_type; /* Size of allocated memory [bytes] */ static size_t * cpl_xmemory_p_size; /*----------------------------------------------------------------------------- Private function prototypes -----------------------------------------------------------------------------*/ static void cpl_xmemory_init(void); static void cpl_xmemory_init_alloc(void); static void cpl_xmemory_end(void); static void cpl_xmemory_resize(void); static void cpl_xmemory_addcell(unsigned, const void *, size_t, unsigned char); static void cpl_xmemory_remcell(unsigned); static unsigned cpl_xmemory_findcell(const void *); static unsigned cpl_xmemory_findfree(const void *); /*----------------------------------------------------------------------------*/ /** * @defgroup cpl_xmemory POSIX-compatible extended memory handling * * cpl_xmemory is a small and efficient module offering memory extension * capabitilies to ANSI C programs running on POSIX-compliant systems. It * offers several useful features such as memory leak detection, protection for * free on NULL or unallocated pointers. * This module has been tested on a number of * current Unix * flavours and is reported to work fine. * The current limitation is the limited number of pointers it can handle at * the same time. */ /*----------------------------------------------------------------------------*/ /**@{*/ /*----------------------------------------------------------------------------- Function codes -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /** @brief malloc() with failure check @param size Size (in bytes) to allocate. @return 1 newly allocated pointer (possibly NULL on zero bytes) @note Will assert()/exit on failure */ /*----------------------------------------------------------------------------*/ inline void * cpl_xmemory_malloc_count(size_t size) { void * ptr = malloc(size); if (ptr != NULL) { cpl_xmemory_ncells++; /* Remember peak allocation */ if (cpl_xmemory_ncells > cpl_xmemory_max_cells) cpl_xmemory_max_cells = cpl_xmemory_ncells; } else if (size != 0) { fprintf(stderr, "cpl_xmemory fatal error: malloc(%lu) returned NULL\n", (long unsigned)size); cpl_xmemory_status(1); assert(ptr != NULL); exit(-1); } return ptr; } /*----------------------------------------------------------------------------*/ /** @brief calloc() with failure check @param nmemb Number of elements to allocate. @param size Size (in bytes) to allocate. @return 1 newly allocated pointer (possibly NULL on zero bytes) @note Will assert()/exit on failure */ /*----------------------------------------------------------------------------*/ inline void * cpl_xmemory_calloc_count(size_t nmemb, size_t size) { void * ptr = calloc(nmemb, size); if (ptr != NULL) { cpl_xmemory_ncells++; /* Remember peak allocation */ if (cpl_xmemory_ncells > cpl_xmemory_max_cells) cpl_xmemory_max_cells = cpl_xmemory_ncells; } else if (size != 0 && nmemb != 0) { fprintf(stderr, "cpl_xmemory fatal error: calloc(%lu, %lu) returned " "NULL\n",(long unsigned)nmemb, (long unsigned)size); cpl_xmemory_status(1); assert(ptr != NULL); exit(-1); } return ptr; } /*----------------------------------------------------------------------------*/ /** @brief realloc() with failure check @param oldptr Pointer to reallocate. @param size Size (in bytes) to reallocate. @return 1 newly allocated pointer (possibly NULL on zero bytes) @note Will assert()/exit on failure */ /*----------------------------------------------------------------------------*/ inline void * cpl_xmemory_realloc_count(void * oldptr, size_t size) { void * ptr; if (oldptr == NULL) { ptr = cpl_xmemory_malloc_count(size); } else if (cpl_xmemory_ncells == 0) { fprintf(stderr, "cpl_xmemory error: Ignoring realloc() to %lu bytes on " "unallocated pointer (%p)\n", (long unsigned)size, oldptr); ptr = NULL; } else { /* assert( oldptr != NULL ); */ ptr = realloc(oldptr, size); if (ptr == NULL) { /* assert( cpl_xmemory_ncells != 0 ); */ cpl_xmemory_ncells--; if (size != 0) { fprintf(stderr, "cpl_xmemory fatal error: realloc(%p, %lu) " "returned NULL\n",oldptr, (long unsigned)size); cpl_xmemory_status(1); assert(ptr != NULL); exit(-1); } } } return ptr; } /*----------------------------------------------------------------------------*/ /** @brief Free memory. @param ptr Pointer to free. @return void @see free() */ /*----------------------------------------------------------------------------*/ void cpl_xmemory_free_count(void * ptr) { if (ptr != NULL) { if (cpl_xmemory_ncells == 0) { fprintf(stderr, "cpl_xmemory error: Ignoring free() on " "unallocated pointer (%p)\n", ptr); } else { cpl_xmemory_ncells--; free(ptr); } } return; } /*----------------------------------------------------------------------------*/ /** @brief Allocate memory. @param size Size (in bytes) to allocate. @return 1 newly allocated pointer. This function is a replacement call for malloc. It should never be called directly but through a macro instead, as: @code cpl_xmemory_malloc(size) @endcode */ /*----------------------------------------------------------------------------*/ void * cpl_xmemory_malloc(size_t size) { void * ptr; unsigned pos; if (size == 0) { /* In this case it is allowed to return NULL - do that and save space in the table */ return NULL; } /* Initialize table if needed */ if (cpl_xmemory_initialized == 0) { cpl_xmemory_init(); } ptr = cpl_xmemory_malloc_count(size); if (cpl_xmemory_ncells >= cpl_xmemory_table_size * CPL_XMEMORY_RESIZE_THRESHOLD) { /* Memory table is too full, resize */ cpl_xmemory_resize(); } /* Add cell into general table */ pos = cpl_xmemory_findfree(ptr); cpl_xmemory_addcell(pos, ptr, size, CPL_XMEMORY_TYPE_MALLOC); return ptr; } /*----------------------------------------------------------------------------*/ /** @brief Allocate memory. @param nmemb Number of elements to allocate. @param size Size (in bytes) of each element. @return 1 newly allocated pointer. */ /*----------------------------------------------------------------------------*/ void * cpl_xmemory_calloc(size_t nmemb, size_t size) { void * ptr; unsigned pos; if (size == 0 || nmemb == 0) { /* In this case it is allowed to return NULL - do that and save space in the table */ return NULL; } /* Initialize table if needed */ if (cpl_xmemory_initialized == 0) { cpl_xmemory_init(); } ptr = cpl_xmemory_calloc_count(nmemb, size); if (cpl_xmemory_ncells >= cpl_xmemory_table_size * CPL_XMEMORY_RESIZE_THRESHOLD) { /* Memory table is too full, resize */ cpl_xmemory_resize(); } /* Add cell into general table */ pos = cpl_xmemory_findfree(ptr); cpl_xmemory_addcell(pos, ptr, nmemb * size, CPL_XMEMORY_TYPE_CALLOC); return ptr; } /*----------------------------------------------------------------------------*/ /** @brief Re-Allocate memory. @param oldptr Pointer to free. @param size Size (in bytes) to allocate. @return 1 newly allocated pointer. */ /*----------------------------------------------------------------------------*/ void * cpl_xmemory_realloc(void * oldptr, size_t size) { void * ptr; unsigned pos = cpl_xmemory_table_size; /* Avoid (false) uninit warning */ if (size == 0) { /* In this case it is allowed to return NULL - do that and save space in the table */ cpl_xmemory_free(oldptr); return NULL; } /* Initialize table if needed */ if (cpl_xmemory_initialized == 0) { cpl_xmemory_init(); } if (oldptr != NULL) { pos = cpl_xmemory_findcell(oldptr); if (pos == cpl_xmemory_table_size) { fprintf(stderr, "cpl_xmemory error: Ignoring realloc() of %lu bytes" " requested on unallocated pointer (%p)\n", (unsigned long) size, oldptr); return NULL; } if (size == cpl_xmemory_p_size[pos]) { /* No actual realloc() is needed, so just update the allocation type since the caller will expect the pointer to come from realloc(). */ cpl_xmemory_p_type[pos] = CPL_XMEMORY_TYPE_REALLOC; return oldptr; } /* Remove cell from main table */ cpl_xmemory_remcell(pos); } ptr = cpl_xmemory_realloc_count(oldptr, size); /* assert( ptr != NULL ); */ if (ptr != oldptr) { if (cpl_xmemory_ncells >= cpl_xmemory_table_size * CPL_XMEMORY_RESIZE_THRESHOLD) { /* Memory table is too full, resize */ cpl_xmemory_resize(); } pos = cpl_xmemory_findfree(ptr); } /* Add cell into general table */ cpl_xmemory_addcell(pos, ptr, size, CPL_XMEMORY_TYPE_REALLOC); return ptr; } /*----------------------------------------------------------------------------*/ /** @brief Free memory. @param ptr Pointer to free. @return void @note Nothing is done on NULL @see free() Free the memory associated to a given pointer. Prints a warning on stderr if the requested pointer cannot be found in the memory table. */ /*----------------------------------------------------------------------------*/ void cpl_xmemory_free(void * ptr) { unsigned pos; /* Do nothing for a NULL pointer */ if (ptr == NULL) return; if (cpl_xmemory_ncells == 0) { fprintf(stderr, "cpl_xmemory error: Ignoring free() on " "unallocated pointer (%p)\n", ptr); return; } /* Initialize table if needed */ if (cpl_xmemory_initialized == 0) { cpl_xmemory_init(); } pos = cpl_xmemory_findcell(ptr); if (pos == cpl_xmemory_table_size) { fprintf(stderr, "cpl_xmemory error: Ignoring free() on unallocated " "pointer (%p)\n", ptr); return; } /* Decrement number of allocated pointers */ cpl_xmemory_ncells--; /* Remove cell from main table */ cpl_xmemory_remcell(pos); /* Free memory */ free(ptr); /* There are no more active pointers, deallocate internal memory */ if (cpl_xmemory_ncells == 0) cpl_xmemory_end(); return; } /*----------------------------------------------------------------------------*/ /** @brief Display memory status information. @param mode Mode (0: system, 1: Xmemory-failure check, 2: Xmemory-full) @return void This function is meant for debugging purposes, but it is recommended to call it at the end of every executable making use of the extended memory features. */ /*----------------------------------------------------------------------------*/ void cpl_xmemory_status(int mode) { if (mode > 0) { const size_t rowsize = sizeof(void*) + sizeof(size_t)+ sizeof(unsigned char); fprintf(stderr, "#----- Memory Diagnostics -----\n"); if (mode == 2) { fprintf(stderr, "Peak pointer usage [pointer]: %u\n" "Peak memory allocation [B]: %lu\n" "Peak table size [pointer]: %lu\n" "Peak table size [B]: %lu\n", cpl_xmemory_max_cells, (unsigned long)cpl_xmemory_alloc_max, (unsigned long)cpl_xmemory_table_size_max, (unsigned long)(cpl_xmemory_table_size_max*rowsize)); } else { fprintf(stderr, "Maximum number of pointers: %u\n", cpl_xmemory_max_cells); } fprintf(stderr, "#----- Memory Currently Allocated -----\n"); fprintf(stderr, "Number of active pointers: %u\n", cpl_xmemory_ncells); if (mode == 2 && cpl_xmemory_ncells > 0) { unsigned ii; unsigned ntype[4] = {0, 0, 0, 0}; /* assert( cpl_xmemory_initialized != 0 ); */ fprintf(stderr, "Memory allocation [B]: %lu\n" "Current table size [pointer]: %u\n" "Current table size [B]: %lu\n", (unsigned long)cpl_xmemory_alloc_ram, (unsigned)cpl_xmemory_table_size, (unsigned long)(cpl_xmemory_table_size*rowsize)); fprintf(stderr, "#- Active pointer details\n"); for (ii=0; ii < cpl_xmemory_table_size; ii++) { if (cpl_xmemory_p_type[ii] != CPL_XMEMORY_TYPE_FREE) { ntype[cpl_xmemory_p_type[ii]]++; fprintf(stderr, "(%p) - %s() of %lu bytes\n", cpl_xmemory_p_val[ii], cpl_xmemory_type[cpl_xmemory_p_type[ii]], (unsigned long)cpl_xmemory_p_size[ii]); } } fprintf(stderr, "#- Types of active pointers\n"); fprintf(stderr, "%7s(): %u\n", cpl_xmemory_type[1], ntype[1]); fprintf(stderr, "%7s(): %u\n", cpl_xmemory_type[2], ntype[2]); fprintf(stderr, "%7s(): %u\n", cpl_xmemory_type[3], ntype[3]); } } return; } /*----------------------------------------------------------------------------*/ /** @brief Tell if there is still some memory allocated @param mode Mode (0: system, 1: Xmemory-failure check, 2: Xmemory-full) @return 1 if the memory table is empty, 0 if no, -1 if the memory model is off */ /*----------------------------------------------------------------------------*/ int cpl_xmemory_is_empty(int mode) { if (mode > 0) { assert(cpl_xmemory_ncells > 0 || cpl_xmemory_alloc_ram == 0); if (mode == 2) assert(cpl_xmemory_ncells == 0 || cpl_xmemory_alloc_ram > 0); return cpl_xmemory_ncells == 0 ? 1 : 0; } else { return -1; } } /**@}*/ /*----------------------------------------------------------------------------*/ /** @internal @brief Initialize extended memory features. @return void This function is implicitly called by the first of xmemory_alloc() and xmemory_free(). It allocates a minimal number of memory cells into the global extended memory table. It also install atexit routines the first time it is called, and increases the number of possible descriptors to the maximum. */ /*----------------------------------------------------------------------------*/ static void cpl_xmemory_init(void) { if (CPL_XMEMORY_RESIZE_THRESHOLD > 1.0) { fprintf(stderr, "cpl_xmemory fatal error: Memory table resize threshold " CPL_XSTRINGIFY(CPL_XMEMORY_RESIZE_THRESHOLD) " must be less " "than or equal to 1, not " CPL_STRINGIFY(CPL_XMEMORY_RESIZE_THRESHOLD) "\n"); assert(CPL_XMEMORY_RESIZE_THRESHOLD <= 1.0); exit(-1); } else if (CPL_XMEMORY_RESIZE_THRESHOLD <= 0.0) { fprintf(stderr, "cpl_xmemory fatal error: Memory table resize threshold " CPL_XSTRINGIFY(CPL_XMEMORY_RESIZE_THRESHOLD) " must be positive" ", not " CPL_STRINGIFY(CPL_XMEMORY_RESIZE_THRESHOLD) "\n"); assert(CPL_XMEMORY_RESIZE_THRESHOLD > 0.0); exit(-1); } if (CPL_XMEMORY_RESIZE_FACTOR <= 1.0) { fprintf(stderr, "cpl_xmemory fatal error: Memory table resize factor " CPL_XSTRINGIFY(CPL_XMEMORY_RESIZE_FACTOR) " must be greater " "than 1, not " CPL_STRINGIFY(CPL_XMEMORY_RESIZE_FACTOR) "\n"); assert(CPL_XMEMORY_RESIZE_FACTOR > 1.0); exit(-1); } cpl_xmemory_table_size = CPL_XMEMORY_MAXPTRS; cpl_xmemory_initialized = 1; cpl_xmemory_init_alloc(); return; } /*----------------------------------------------------------------------------*/ /** @internal @brief Allocate memory for memory features. @return void @note This allocation is done directly with calloc() */ /*----------------------------------------------------------------------------*/ static void cpl_xmemory_init_alloc(void) { cpl_xmemory_p_val = calloc(cpl_xmemory_table_size, sizeof(void*)); cpl_xmemory_p_type = calloc(cpl_xmemory_table_size, sizeof(unsigned char)); cpl_xmemory_p_size = malloc(cpl_xmemory_table_size * sizeof(size_t)); if (cpl_xmemory_p_val == NULL || cpl_xmemory_p_size == NULL || cpl_xmemory_p_type == NULL) { /* The table could not be allocated */ fprintf(stderr, "cpl_xmemory fatal error: calloc() of memory table " "failed with size %u\n", cpl_xmemory_table_size); assert(cpl_xmemory_p_val != NULL); assert(cpl_xmemory_p_size != NULL); assert(cpl_xmemory_p_type != NULL); exit(-1); } if (cpl_xmemory_table_size > cpl_xmemory_table_size_max) cpl_xmemory_table_size_max = cpl_xmemory_table_size; return; } /*----------------------------------------------------------------------------*/ /** @internal @brief Resize the pointer allocation table @return void */ /*----------------------------------------------------------------------------*/ static void cpl_xmemory_resize(void) { const void ** p_val = cpl_xmemory_p_val; const size_t * p_size = cpl_xmemory_p_size; const unsigned char * p_type = cpl_xmemory_p_type; const unsigned old_size = cpl_xmemory_table_size; unsigned ii; assert( cpl_xmemory_table_size > 0 ); assert( cpl_xmemory_initialized == 1 ); assert( cpl_xmemory_ncells > 0 ); cpl_xmemory_table_size = cpl_xmemory_table_size * CPL_XMEMORY_RESIZE_FACTOR; /* Ensure that the table size is odd, to reduce hashing clashed */ cpl_xmemory_table_size |= 1; if (cpl_xmemory_table_size <= old_size) { /* The table could not be resized */ fprintf(stderr, "cpl_xmemory fatal error: Memory table could not be " "resized, %u < %u \n", cpl_xmemory_table_size, old_size); assert(cpl_xmemory_table_size > old_size); exit(-1); } cpl_xmemory_init_alloc(); /* Locate pointer in main table */ for (ii = 0; ii < old_size; ii++) { if (p_type[ii]) { /* Old table has a pointer here */ /* Find position in enlarged table */ const unsigned pos = cpl_xmemory_findfree(p_val[ii]); /* Duplicated from cpl_xmemory_addcell() */ cpl_xmemory_p_val[pos] = p_val[ii]; cpl_xmemory_p_size[pos] = p_size[ii]; cpl_xmemory_p_type[pos] = p_type[ii]; } } free((void*)p_val); free((void*)p_size); free((void*)p_type); return; } /*----------------------------------------------------------------------------*/ /** @internal @brief Deinitialize extended memory features. @return void */ /*----------------------------------------------------------------------------*/ static void cpl_xmemory_end(void) { assert( cpl_xmemory_ncells == 0 ); cpl_xmemory_table_size = 0; cpl_xmemory_initialized = 0; free(cpl_xmemory_p_val); free(cpl_xmemory_p_type); free(cpl_xmemory_p_size); return; } /*----------------------------------------------------------------------------*/ /** @internal @brief Add allocation cell. @param pos Position in the table @param pointer Pointer value. @param size Pointer size. @param type Allocation type @return void Add a memory cell in the xtended memory table to register that a new allocation took place. This call is not protected against illegal parameter values, so make sure the passed values are correct! */ /*----------------------------------------------------------------------------*/ inline static void cpl_xmemory_addcell(unsigned pos, const void * pointer, size_t size, unsigned char type) { /* Store information */ cpl_xmemory_p_val[pos] = pointer; cpl_xmemory_p_size[pos] = size; /* Allocation type */ cpl_xmemory_p_type[pos] = type; cpl_xmemory_alloc_ram += size; /* Remember peak allocation */ if (cpl_xmemory_alloc_ram > cpl_xmemory_alloc_max) cpl_xmemory_alloc_max = cpl_xmemory_alloc_ram; return; } /*----------------------------------------------------------------------------*/ /** @internal @brief Find the cell of a given pointer @param ptr Xmemory-allocated pointer, i.e. not NULL @return Index of cell with pointer, or cpl_xmemory_table_size when not found */ /*----------------------------------------------------------------------------*/ inline static unsigned cpl_xmemory_findcell(const void * ptr) { unsigned ii; unsigned pos = PTR_HASH(ptr); /* Locate pointer in main table */ for (ii=0; ii < cpl_xmemory_table_size; ii++) { if (cpl_xmemory_p_val[pos] == ptr) break; if (++pos == cpl_xmemory_table_size) pos = 0; } return ii == cpl_xmemory_table_size ? cpl_xmemory_table_size : pos; } /*----------------------------------------------------------------------------*/ /** @internal @brief Find the first free cell suitable for the pointer @param ptr Allocated pointer to keep in Xmemory @return Index of cell with pointer @note This function will exit when the table is full */ /*----------------------------------------------------------------------------*/ inline static unsigned cpl_xmemory_findfree(const void * ptr) { /* Find an available slot */ unsigned pos = PTR_HASH(ptr); /* In comparison with the method of cpl_xmemory_findcell() this is faster when the table starts to be full */ const void * ppos = memchr(cpl_xmemory_p_type+pos, CPL_XMEMORY_TYPE_FREE, (size_t)(cpl_xmemory_table_size-pos)); if (ppos == NULL) { ppos = memchr(cpl_xmemory_p_type, CPL_XMEMORY_TYPE_FREE, (size_t)pos); if (ppos == NULL) { /* No available slot */ fprintf(stderr, "cpl_xmemory internal, fatal error: Could not find " "place for new pointer\n"); cpl_xmemory_status(2); assert(ppos != NULL); exit(-1); } } return (unsigned)((unsigned long)ppos - (unsigned long)cpl_xmemory_p_type); } /*----------------------------------------------------------------------------*/ /** @internal @brief Remove a memory cell from the xtended memory table. @param pos Position of the pointer in the table. @return void Remove the specified cell. This call is not protected against illegal parameter values, so make sure the passed values are correct! */ /*----------------------------------------------------------------------------*/ inline static void cpl_xmemory_remcell(unsigned pos) { /* Set pointer to NULL */ cpl_xmemory_p_val[pos] = NULL; /* Set type to free */ cpl_xmemory_p_type[pos] = CPL_XMEMORY_TYPE_FREE; cpl_xmemory_alloc_ram -= cpl_xmemory_p_size[pos]; return; }