mi32/memalloc.h

Go to the documentation of this file.
00001 /**
00002  * \file memalloc.h mi32/memalloc.h
00003  * \brief Memory allocation functions
00004  *
00005  * \if NODOC
00006  * $Id: memalloc.h_v 1.1 2005/07/14 17:28:22 mju Exp $
00007  *
00008  * $Log: memalloc.h_v $
00009  * Revision 1.1  2005/07/14 17:28:22  mju
00010  * Initial revision
00011  *
00012  * \endif
00013 **/
00014 
00015 #ifndef  INC_MI32_MEMALLOC_H
00016 #define  INC_MI32_MEMALLOC_H
00017 
00018 #ifndef  INC_MI32_STDDEFNS_H
00019 #include <mi32/stddefns.h>
00020 #endif
00021 
00022 #ifndef  INC_STDLIB_H
00023 #include <stdlib.h>        // for free()
00024 #define  INC_STDLIB_H
00025 #endif
00026 
00027 #ifdef MISYSTEMDLL
00028    #define LIBEXPORT MI_DLLEXPORT
00029 #else
00030    #define LIBEXPORT MI_DLLIMPORT
00031 #endif
00032 
00033 
00034 //!\addtogroup Mm Memory Allocation Functions (Mm)
00035 //!@{
00036 
00037 //! Free a pointer and set it's value to NULL.
00038 #if defined(__cplusplus)
00039 template <class _CT> inline void MmFree(_CT *& p) { if (p != 0) { free(p); p = NULL; } }
00040 #elif !defined(GENERATING_DOXYGEN_OUTPUT)
00041 #define  MmFree(p)      do {if ((p) != NULL) {free((p));(p) = NULL;}} while (0)
00042 #endif
00043 
00044 #if defined(__cplusplus)
00045 extern "C" {
00046 #endif
00047 
00048 //! Allocate memory - Return error on failure.
00049 //!
00050 //! Returns error code if allocation fails.
00051 //! Example:
00052 //! @code
00053 //!    UINT8* buf;
00054 //!    err = MmAlloc((void**)&buf, size);
00055 //!    if (err < 0) return(SetErrPosn(err));
00056 LIBEXPORT ERRVALUE MmAlloc (
00057    void** ptr,                         //!< Pointer to memory allocated and returned
00058    int size                            //!< Size to allocate in bytes
00059    );
00060 
00061 //! Allocate and clear memory - Return error on failure.
00062 //! @see MmAlloc()
00063 LIBEXPORT ERRVALUE MmAllocC (
00064    void** ptr,                         //!< Pointer to memory allocated and returned
00065    int size                            //!< Size to allocate in bytes
00066    );
00067 
00068 //! Allocate and clear memory - Throw exception of failure.
00069 //! @see MmAlloc()
00070 LIBEXPORT void MmAllocCExc (
00071    void** ptr,                         //!< Pointer to memory allocated and returned
00072    int size                            //!< Size to allocate in bytes
00073    );
00074 
00075 //! Allocate memory - Throw exception of failure.
00076 //! @see MmAlloc()
00077 LIBEXPORT void MmAllocExc (
00078    void** ptr,                         //!< Pointer to memory allocated and returned
00079    int size                            //!< Size to allocate in bytes
00080    );
00081 
00082 //! Resize memory buffer, retaining existing contents - Return error on failure.
00083 //! @see MmAlloc()
00084 LIBEXPORT ERRVALUE MmRealloc (
00085    void** ptr,                         //!< Pointer to memory to reallocate and returned
00086    int newsize                         //!< New size in bytes
00087    );
00088 
00089 #if defined(__cplusplus)
00090 //! Resize memory buffer and clear new part - Return error on failure.
00091 //! @see MmAlloc()
00092 LIBEXPORT ERRVALUE MmReallocC (
00093    void** ptr,                         //!< Pointer to memory to reallocate and returned
00094    int newsize,                        //!< New size in bytes
00095    int oldsize = 0                     //!< Size of portion to not clear in bytes
00096    );
00097 #elif !defined(GENERATING_DOXYGEN_OUTPUT) //  normal "C" 
00098 LIBEXPORT ERRVALUE MmReallocC (
00099    void** ptr,                         //!< Pointer to memory to reallocate and returned
00100    int newsize,                        //!< New size in bytes
00101    int oldsize                         //!< Size of portion to not clear in bytes
00102    );
00103 #endif
00104 
00105 #if defined(__cplusplus)
00106 //! Resize memory buffer and clear new part - Throw exception on failure.
00107 //! @see MmAlloc()
00108 LIBEXPORT void MmReallocCExc (
00109    void** ptr,                         //!< Pointer to memory to reallocate and returned
00110    int newsize,                        //!< New size in bytes
00111    int oldsize = 0                     //!< Size of portion to not clear in bytes
00112    );
00113 #endif
00114 
00115 #if defined(__cplusplus)
00116 //! Resize memory buffer, discarding existing contents - Return error on failure.
00117 //! @see MmAlloc()
00118 inline ERRVALUE MmReallocD (
00119    void** ptr,                         //!< Pointer to memory to reallocate and returned
00120    int newsize                         //!< New size in bytes
00121    ) {
00122    if (*ptr != 0) {
00123       free(*ptr);
00124       }
00125    return (MmAlloc(ptr,newsize));
00126    }
00127 #endif
00128 
00129 #if defined(__cplusplus)
00130 //! Resize memory buffer, discarding existing contents - Throw exception on failure.
00131 //! @see MmAlloc()
00132 inline void MmReallocDExc (
00133    void** ptr,                         //!< Pointer to memory to reallocate and returned
00134    int newsize                         //!< New size in bytes
00135    ) {
00136    if (*ptr != 0) {
00137       free(*ptr);
00138       }
00139    MmAllocExc(ptr,newsize);
00140    return;
00141    }
00142 #endif
00143 
00144 #if defined(__cplusplus)
00145 //! Resize memory buffer, retaining existing contents - Throw exception on failure.
00146 //! @see MmAlloc()
00147 LIBEXPORT void MmReallocExc (
00148    void** ptr,                         //!< Pointer to memory to reallocate and returned
00149    int newsize                         //!< New size in bytes
00150    );
00151 #endif
00152 
00153 #if defined(__cplusplus)
00154 }
00155 #endif
00156 
00157 //!@}
00158 
00159 #undef LIBEXPORT
00160 
00161 #endif   // INC_MI32_MEMALLOC_H

Generated on Thu Apr 26 04:04:16 2007 for TNTsdk by  doxygen 1.5.2