⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libmpalloc.html

📁 debug source code under unix platform.
💻 HTML
字号:
Content-type: text/html<HTML><HEAD><TITLE>Manpage of LIBMPALLOC</TITLE></HEAD><BODY><H1>LIBMPALLOC</H1>Section: mpatrol library (3)<BR>Updated: 8 January 2002<BR><A HREF="#index">Index</A><A HREF="http://localhost/cgi-bin/man/man2html">Return to Main Contents</A><HR><A NAME="lbAB">&nbsp;</A><H2>NAME</H2>libmpalloc - dynamic memory allocation replacement library<A NAME="lbAC">&nbsp;</A><H2>SYNOPSIS</H2><PRE>#include &lt;<A HREF="file:/usr/include/mpalloc.h">mpalloc.h</A>&gt;void *MP_MALLOC(void *ptr, size_t count, typename type);void *MP_CALLOC(void *ptr, size_t count, typename type);char *MP_STRDUP(char *ptr, const char *str);void *MP_REALLOC(void *ptr, size_t count, typename type);void MP_FREE(void *ptr);__mp_failhandler MP_FAILURE(__mp_failhandler func);</PRE><A NAME="lbAD">&nbsp;</A><H2>DESCRIPTION</H2>The <I>mpalloc library</I> contains release implementations of all of the mpatrollibrary functions, with all of its checking, debugging and tracing featuresdisabled.  It is fully link-compatible with the mpatrol library and so can belinked in instead of the mpatrol library in order to quickly disable all of itsfeatures without requiring a complete recompilation of all of the source filesin a project.  It also contains implementations of the <B>MP_MALLOC</B> familyof functions that can be used in a release environment.<P>All of the function definitions in <I>mpatrol.h</I> can be disabled by definingthe <B>NDEBUG</B> preprocessor macro, which is the same macro used to controlthe behaviour of the <B>assert</B> function.  If <B>NDEBUG</B> is defined thenno macro redefinition of functions will take place and all special mpatrollibrary functions will evaluate to empty statements.  The <I>mpalloc.h</I> headerfile will also be included in this case.  It is intended that the <B>NDEBUG</B>preprocessor macro be defined in release builds.<P>The mpalloc library contains functional replacements for all of the mpatrollibrary's dynamic memory allocation and memory operation functions, mainly foruse in situations where not all of the source files in a project have beenrecompiled with the <B>NDEBUG</B> preprocessor macro in order to remove mpatrol.However, not all of these functions can be fully implemented using ANSI C and somay contain some limitations.  The only recommended solution for a final releaseis to perform a complete recompile with <B>NDEBUG</B> defined.<A NAME="lbAE">&nbsp;</A><H2>FUNCTIONS</H2>The following 6 functions are provided as convenient alternatives to the ANSI Cdynamic memory allocation functions (although <B>strdup</B> is not strictly anANSI C function).  They are implemented as preprocessor macro functions whichmay evaluate their arguments more than once, so extra care should be taken toavoid passing arguments with side-effects.  None of the functions return<B>NULL</B> if no memory is available and instead abort the program with a usefulerror message indicating where the call to allocate memory came from and whatwas being allocated.  To use these you should include the <I>mpalloc.h</I> headerfile:<DL COMPACT><DT><B>MP_MALLOC</B><DD>Allocates <I>count</I> uninitialised items of type <I>type</I> from the heap, sets<I>ptr</I> to the result and returns a suitably-cast pointer to the first item ofthe allocation.  The pointer returned will be suitably aligned for holding itemsof type <I>type</I>.  If <I>count</I> is <I>0</I> then it will be implicitlyrounded up to <I>1</I>.  If there is not enough space in the heap then theprogram will be aborted after calling the allocation failure handler, which bydefault writes an appropriate error message to the standard error file stream.The allocated memory in <I>ptr</I> must be deallocated with <B>MP_FREE</B> orreallocated with <B>MP_REALLOC</B>.<DT><B>MP_CALLOC</B><DD>Allocates <I>count</I> zero-initialised items of type <I>type</I> from the heap,sets <I>ptr</I> to the result and returns a suitably-cast pointer to the firstitem of the allocation.  The pointer returned will be suitably aligned forholding items of type <I>type</I>.  If <I>count</I> is <I>0</I> then it will beimplicitly rounded up to <I>1</I>.  If there is not enough space in the heap thenthe program will be aborted after calling the allocation failure handler, whichby default writes an appropriate error message to the standard error filestream.  The allocated memory in <I>ptr</I> must be deallocated with<B>MP_FREE</B> or reallocated with <B>MP_REALLOC</B>.<DT><B>MP_STRDUP</B><DD>Allocates exactly enough memory from the heap to duplicate <I>str</I> (includingthe terminating nul character), sets <I>ptr</I> to the result and returns asuitably-cast pointer to the first byte of the allocation after copying<I>str</I> to the newly-allocated memory.  The pointer returned will have noalignment constraints and can be used to store character data up to the lengthof <I>str</I>.  If there is not enough space in the heap then the program will beaborted after calling the allocation failure handler, which by default writes anappropriate error message to the standard error file stream.  The allocatedmemory in <I>ptr</I> must be deallocated with <B>MP_FREE</B> or reallocated with<B>MP_REALLOC</B>.<DT><B>MP_REALLOC</B><DD>Resizes the memory allocation beginning at <I>ptr</I> to <I>count</I> items oftype <I>type</I> and returns a suitably-cast pointer to the first item of the newallocation after copying <I>ptr</I> to the newly-allocated memory, which will betruncated if <I>count</I> is smaller than the original number of items.  Thepointer returned will be suitably aligned for holding items of type <I>type</I>.If <I>ptr</I> is <B>NULL</B> then the call will be equivalent to <B>MP_MALLOC</B>.If <I>count</I> is <I>0</I> then it will be implicitly rounded up to <I>1</I>.  If<I>count</I> is greater than the original number of items then the extra spacewill be filled with uninitialised bytes.  If there is not enough space in theheap then the program will be aborted after calling the allocation failurehandler, which by default writes an appropriate error message to the standarderror file stream.  The allocated memory must be deallocated with <B>MP_FREE</B>and can be reallocated again with <B>MP_REALLOC</B>.<DT><B>MP_FREE</B><DD>Frees the memory allocation beginning at <I>ptr</I> so the memory can be reusedby another call to allocate memory, and sets <I>ptr</I> to <B>NULL</B> afterfreeing the memory.  If <I>ptr</I> is <B>NULL</B> then no memory will be freed.<DT><B>MP_FAILURE</B><DD>Installs an allocation failure handler specifically for use with<B>MP_MALLOC</B>, <B>MP_CALLOC</B>, <B>MP_STRDUP</B> and <B>MP_REALLOC</B> andreturns a pointer to the previously installed handler, normally the defaulthandler if no handler had been previously installed.  This will be called bythe above functions when there is not enough space in the heap for them tosatisfy their allocation request.  The default allocation failure handler willterminate the program after writing an error message to the standard error filestream indicating where the original allocation request took place and what wasbeing allocated.</DL><A NAME="lbAF">&nbsp;</A><H2>SEE ALSO</H2><B><A HREF="http://localhost/cgi-bin/man/man2html?1+mpatrol">mpatrol</A></B>(1), <B><A HREF="http://localhost/cgi-bin/man/man2html?1+mprof">mprof</A></B>(1), <B><A HREF="http://localhost/cgi-bin/man/man2html?1+mptrace">mptrace</A></B>(1), <B><A HREF="http://localhost/cgi-bin/man/man2html?1+mleak">mleak</A></B>(1),<B><A HREF="http://localhost/cgi-bin/man/man2html?1+mpsym">mpsym</A></B>(1), <B><A HREF="http://localhost/cgi-bin/man/man2html?1+mpedit">mpedit</A></B>(1), <B><A HREF="http://localhost/cgi-bin/man/man2html?1+hexwords">hexwords</A></B>(1), <B><A HREF="http://localhost/cgi-bin/man/man2html?3+libmpatrol">libmpatrol</A></B>(3),<B><A HREF="http://localhost/cgi-bin/man/man2html?3+malloc">malloc</A></B>(3), <B><A HREF="http://localhost/cgi-bin/man/man2html?3+assert">assert</A></B>(3).<P>The mpatrol manual and reference card.<P><A HREF="http://www.cbmamiga.demon.co.uk/mpatrol/">http://www.cbmamiga.demon.co.uk/mpatrol/</A><A NAME="lbAG">&nbsp;</A><H2>AUTHOR</H2>Graeme S. Roy &lt;<A HREF="mailto:graeme.roy@analog.com">graeme.roy@analog.com</A>&gt;<A NAME="lbAH">&nbsp;</A><H2>COPYRIGHT</H2>Copyright (C) 1997-2002 Graeme S. Roy &lt;<A HREF="mailto:graeme.roy@analog.com">graeme.roy@analog.com</A>&gt;<P>This library is free software; you can redistribute it and/or modify it underthe terms of the GNU Library General Public License as published by the FreeSoftware Foundation; either version 2 of the License, or (at your option) anylater version.<P>This library is distributed in the hope that it will be useful, but WITHOUTANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESSFOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for moredetails.<P>You should have received a copy of the GNU Library General Public Licensealong with this library; if not, write to the Free Software Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.<P><HR><A NAME="index">&nbsp;</A><H2>Index</H2><DL><DT><A HREF="#lbAB">NAME</A><DD><DT><A HREF="#lbAC">SYNOPSIS</A><DD><DT><A HREF="#lbAD">DESCRIPTION</A><DD><DT><A HREF="#lbAE">FUNCTIONS</A><DD><DT><A HREF="#lbAF">SEE ALSO</A><DD><DT><A HREF="#lbAG">AUTHOR</A><DD><DT><A HREF="#lbAH">COPYRIGHT</A><DD></DL><HR>This document was created by<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,using the manual pages.<BR>Time: 23:42:08 GMT, January 08, 2002</BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -