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

📄 libmpalloc.3

📁 debug source code under unix platform.
💻 3
字号:
.\" mpatrol.\" A library for controlling and tracing dynamic memory allocations..\" Copyright (C) 1997-2002 Graeme S. Roy <graeme.roy@analog.com>.\".\" This library is free software; you can redistribute it and/or.\" modify it under the terms of the GNU Library General Public.\" License as published by the Free Software Foundation; either.\" version 2 of the License, or (at your option) any later version..\".\" This library 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.\" Library General Public License for more details..\".\" You should have received a copy of the GNU Library General Public.\" License along with this library; if not, write to the Free.\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,.\" MA 02111-1307, USA..\".\" UNIX Manual Page.\".\" $Id: libmpalloc.3,v 1.4 2002/01/08 20:28:42 graeme Exp $.\".TH LIBMPALLOC 3 "8 January 2002" "Release 1.4" "mpatrol library".SH NAMElibmpalloc \- dynamic memory allocation replacement library.SH SYNOPSIS.nf#include <mpalloc.h>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);.fi.SH DESCRIPTIONThe \fImpalloc library\fP 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 \fBMP_MALLOC\fP familyof functions that can be used in a release environment..PPAll of the function definitions in \fImpatrol.h\fP can be disabled by definingthe \fBNDEBUG\fP preprocessor macro, which is the same macro used to controlthe behaviour of the \fBassert\fP function.  If \fBNDEBUG\fP is defined thenno macro redefinition of functions will take place and all special mpatrollibrary functions will evaluate to empty statements.  The \fImpalloc.h\fP headerfile will also be included in this case.  It is intended that the \fBNDEBUG\fPpreprocessor macro be defined in release builds..PPThe 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 \fBNDEBUG\fP 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 \fBNDEBUG\fP defined..SH FUNCTIONSThe following 6 functions are provided as convenient alternatives to the ANSI Cdynamic memory allocation functions (although \fBstrdup\fP 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\fBNULL\fP 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 \fImpalloc.h\fP headerfile:.TP\fBMP_MALLOC\fPAllocates \fIcount\fP uninitialised items of type \fItype\fP from the heap, sets\fIptr\fP 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 \fItype\fP.  If \fIcount\fP is \fI0\fP then it will be implicitlyrounded up to \fI1\fP.  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 \fIptr\fP must be deallocated with \fBMP_FREE\fP orreallocated with \fBMP_REALLOC\fP..TP\fBMP_CALLOC\fPAllocates \fIcount\fP zero-initialised items of type \fItype\fP from the heap,sets \fIptr\fP 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 \fItype\fP.  If \fIcount\fP is \fI0\fP then it will beimplicitly rounded up to \fI1\fP.  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 \fIptr\fP must be deallocated with\fBMP_FREE\fP or reallocated with \fBMP_REALLOC\fP..TP\fBMP_STRDUP\fPAllocates exactly enough memory from the heap to duplicate \fIstr\fP (includingthe terminating nul character), sets \fIptr\fP to the result and returns asuitably-cast pointer to the first byte of the allocation after copying\fIstr\fP to the newly-allocated memory.  The pointer returned will have noalignment constraints and can be used to store character data up to the lengthof \fIstr\fP.  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 \fIptr\fP must be deallocated with \fBMP_FREE\fP or reallocated with\fBMP_REALLOC\fP..TP\fBMP_REALLOC\fPResizes the memory allocation beginning at \fIptr\fP to \fIcount\fP items oftype \fItype\fP and returns a suitably-cast pointer to the first item of the newallocation after copying \fIptr\fP to the newly-allocated memory, which will betruncated if \fIcount\fP is smaller than the original number of items.  Thepointer returned will be suitably aligned for holding items of type \fItype\fP.If \fIptr\fP is \fBNULL\fP then the call will be equivalent to \fBMP_MALLOC\fP.If \fIcount\fP is \fI0\fP then it will be implicitly rounded up to \fI1\fP.  If\fIcount\fP 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 \fBMP_FREE\fPand can be reallocated again with \fBMP_REALLOC\fP..TP\fBMP_FREE\fPFrees the memory allocation beginning at \fIptr\fP so the memory can be reusedby another call to allocate memory, and sets \fIptr\fP to \fBNULL\fP afterfreeing the memory.  If \fIptr\fP is \fBNULL\fP then no memory will be freed..TP\fBMP_FAILURE\fPInstalls an allocation failure handler specifically for use with\fBMP_MALLOC\fP, \fBMP_CALLOC\fP, \fBMP_STRDUP\fP and \fBMP_REALLOC\fP 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..SH SEE ALSO\fBmpatrol\fP(1), \fBmprof\fP(1), \fBmptrace\fP(1), \fBmleak\fP(1),\fBmpsym\fP(1), \fBmpedit\fP(1), \fBhexwords\fP(1), \fBlibmpatrol\fP(3),\fBmalloc\fP(3), \fBassert\fP(3)..PPThe mpatrol manual and reference card..PPhttp://www.cbmamiga.demon.co.uk/mpatrol/.SH AUTHORGraeme S. Roy <graeme.roy@analog.com>.SH COPYRIGHTCopyright (C) 1997-2002 Graeme S. Roy <graeme.roy@analog.com>.PPThis 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..PPThis 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..PPYou 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.

⌨️ 快捷键说明

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