📄 libmpatrol.3
字号:
\fIsize\fP bytes and returns a pointer to the first byte of the new allocationafter copying \fIptr\fP to the newly-allocated memory, which will be truncatedif \fInelem\fP * \fIsize\fP is smaller than the original allocation. Thepointer returned will be suitably aligned for casting to any type and can beused to store data of up to \fInelem\fP * \fIsize\fP bytes in length. If\fIptr\fP is \fBNULL\fP then the call will be equivalent to \fBcalloc\fP. If\fInelem\fP * \fIsize\fP is \fI0\fP then the existing memory allocation will befreed and the null pointer will be returned. If \fInelem\fP * \fIsize\fP isgreater than the original allocation then the extra space will be filled withzero-initialised bytes. If there is not enough space in the heap then the nullpointer will be returned and \fBerrno\fP will be set to \fBENOMEM\fP. Theallocated memory must be deallocated with \fBfree\fP and can be reallocatedagain with \fBrealloc\fP. This function is available for backwardscompatibility with older C libraries and \fBcalloc\fP and should not be used innew code..TP\fBexpand\fPAttempts to resize the memory allocation beginning at \fIptr\fP to \fIsize\fPbytes and either returns \fIptr\fP if there was enough space to resize it, or\fBNULL\fP if the block could not be resized for a particular reason. If\fIptr\fP is \fBNULL\fP then the call will be equivalent to \fBmalloc\fP. If\fIsize\fP is \fB0\fP then the existing memory allocation will be freed and the\fBNULL\fP pointer will be returned. If \fIsize\fP is greater than the originalallocation then the extra space will be filled with uninitialised bytes and if\fIsize\fP is less than the original allocation then the memory block will betruncated. If there is not enough space in the heap then the \fBNULL\fP pointerwill be returned and \fBerrno\fP will be set to \fBENOMEM\fP. The allocatedmemory must be deallocated with \fBfree\fP and can be reallocated again with\fBrealloc\fP. This function is available for backwards compatibility witholder C libraries and should not be used in new code..TP\fBfree\fPFrees the memory allocation beginning at \fIptr\fP so the memory can be reusedby another call to allocate memory. If \fIptr\fP is \fBNULL\fP then no memorywill be freed. All of the previous contents will be destroyed..TP\fBcfree\fPFrees the memory allocation beginning at \fIptr\fP so the memory can be reusedby another call to allocate memory. If \fIptr\fP is \fBNULL\fP then no memorywill be freed. All of the previous contents will be destroyed. The \fInelem\fPand \fIsize\fP parameters are ignored in this implementation. This function isavailable for backwards compatibility with older C libraries and \fBcalloc\fPand should not be used in new code..TP\fBdealloca\fPExplicitly frees the temporary memory allocation beginning at \fIptr\fP so thememory can be reused by another call to allocate memory. If \fIptr\fP is\fBNULL\fP then no memory will be explicitly freed. All of the previouscontents will be destroyed. This function can only be used to free memory thatwas allocated with the \fBalloca\fP, \fBstrdupa\fP and \fBstrndupa\fP functions,but is only really required if the mpatrol library does not automatically freesuch memory allocations when the allocating function returns. This function ismpatrol-specific and should not be used in release code..PPThe following 5 functions are available as replacements for existing C libraryextension functions that always abort and never return \fBNULL\fP if there isinsufficient memory to fulfil a request. To use these you must include\fImpatrol.h\fP before all other header files, although on UNIX and Windowsplatforms (and AmigaOS when using \fBgcc\fP) they will be used anyway, albeitwith slightly less tracing information:.TP\fBxmalloc\fPAllocates \fIsize\fP uninitialised bytes from the heap and returns a pointer tothe first byte of the allocation. The pointer returned will be suitablyaligned for casting to any type and can be used to store data of up to\fIsize\fP bytes in length. If \fIsize\fP is \fI0\fP then the memory allocatedwill be implicitly rounded up to \fI1\fP byte. If there is not enough space inthe heap then the program will be terminated and the \fIOUTMEM\fP error will begiven. The allocated memory must be deallocated with \fBxfree\fP or reallocatedwith \fBxrealloc\fP..TP\fBxcalloc\fPAllocates \fInelem\fP elements of \fIsize\fP zero-initialised bytes from theheap and returns a pointer to the first byte of the allocation. The pointerreturned will be suitably aligned for casting to any type and can be used tostore data of up to \fInelem * size\fP bytes in length. If \fInelem * size\fPis \fI0\fP then the amount of memory allocated will be implicitly rounded up to\fI1\fP byte. If there is not enough space in the heap then the program will beterminated and the \fIOUTMEM\fP error will be given. The allocated memory mustbe deallocated with \fBxfree\fP or reallocated with \fBxrealloc\fP..TP\fBxstrdup\fPAllocates exactly enough memory from the heap to duplicate \fIstr\fP (includingthe terminating nul character) and returns a pointer to the first byte of theallocation after copying \fIstr\fP to the newly-allocated memory. The pointerreturned will have no alignment constraints and can be used to store characterdata up to the length of \fIstr\fP. If \fIstr\fP is \fBNULL\fP then an errorwill be given and the null pointer will be returned. If there is not enoughspace in the heap then the program will be terminated and the \fIOUTMEM\fP errorwill be given. The allocated memory must be deallocated with \fBxfree\fP orreallocated with \fBxrealloc\fP..TP\fBxrealloc\fPResizes the memory allocation beginning at \fIptr\fP to \fIsize\fP bytes andreturns a pointer to the first byte of the new allocation after copying\fIptr\fP to the newly-allocated memory, which will be truncated if \fIsize\fPis smaller than the original allocation. The pointer returned will be suitablyaligned for casting to any type and can be used to store data of up to\fIsize\fP bytes in length. If \fIptr\fP is \fBNULL\fP then the call will beequivalent to \fBxmalloc\fP. If \fIsize\fP is \fI0\fP then it will be implictlyrounded up to \fI1\fP. If \fIsize\fP is greater than the original allocationthen the extra space will be filled with uninitialised bytes. If there is notenough space in the heap then the program will be terminated and the\fIOUTMEM\fP error will be given. The allocated memory must be deallocated with\fBxfree\fP and can be reallocated again with \fBxrealloc\fP..TP\fBxfree\fPFrees the memory allocation beginning at \fIptr\fP so the memory can be reusedby another call to allocate memory. If \fIptr\fP is \fBNULL\fP then no memorywill be freed. All of the previous contents will be destroyed..PPThe following 5 functions are available as replacements for existing C++ libraryfunctions, but the replacements in \fImpatrol.h\fP will only be used if the\fBMP_NOCPLUSPLUS\fP preprocessor macro is not defined. The replacementoperators make use of the preprocessor in order to obtain source-levelinformation. If this causes problems then you should define the\fBMP_NONEWDELETE\fP preprocessor macro and use the \fBMP_NEW\fP,\fBMP_NEW_NOTHROW\fP and \fBMP_DELETE\fP macros instead of \fBnew\fP and\fBdelete\fP directly. To use these C++ features you must include\fImpatrol.h\fP before all other header files, although on UNIX and Windowsplatforms (and AmigaOS when using \fBgcc\fP) they will be used anyway, albeitwith slightly less tracing information:.TP\fBoperator new\fPAllocates \fIsize\fP uninitialised bytes from the heap and returns a pointer tothe first byte of the allocation. The pointer returned will be suitablyaligned for casting to any type and can be used to store data of up to\fIsize\fP bytes in length. If \fIsize\fP is \fI0\fP then the memory allocatedwill be implicitly rounded up to \fI1\fP byte. If there is not enough space inthe heap then either the \fIstd::bad_alloc\fP exception will be thrown or thenull pointer will be returned and \fBerrno\fP will be set to \fBENOMEM\fP - thebehaviour depends on whether the nothrow version of the operator is used. Theallocated memory must be deallocated with \fBoperator delete\fP..TP\fBoperator new[]\fPAllocates \fIsize\fP uninitialised bytes from the heap and returns a pointer tothe first byte of the allocation. The pointer returned will be suitablyaligned for casting to any type and can be used to store data of up to\fIsize\fP bytes in length. If \fIsize\fP is \fI0\fP then the memory allocatedwill be implicitly rounded up to \fI1\fP byte. If there is not enough space inthe heap then either the \fIstd::bad_alloc\fP exception will be thrown or thenull pointer will be returned and \fBerrno\fP will be set to \fBENOMEM\fP - thebehaviour depends on whether the nothrow version of the operator is used. Theallocated memory must be deallocated with \fBoperator delete[]\fP..TP\fBoperator delete\fPFrees the memory allocation beginning at \fIptr\fP so the memory can be reusedby another call to allocate memory. If \fIptr\fP is \fBNULL\fP then no memorywill be freed. All of the previous contents will be destroyed. This functionmust only be used with memory allocated by \fBoperator new\fP..TP\fBoperator delete[]\fPFrees the memory allocation beginning at \fIptr\fP so the memory can be reusedby another call to allocate memory. If \fIptr\fP is \fBNULL\fP then no memorywill be freed. All of the previous contents will be destroyed. This functionmust only be used with memory allocated by \fBoperator new[]\fP..TP\fBset_new_handler\fPInstalls a low-memory handler specifically for use with \fBoperator new\fP and\fBoperator new[]\fP and returns a pointer to the previously installed handler,or the null pointer if no handler had been previously installed. This will becalled repeatedly by both functions when they would normally return \fBNULL\fP,and this loop will continue until they manage to allocate the requested space.Note that this function is equivalent to \fB__mp_nomemory\fP and will replacethe handler installed by that function..PPThe following 10 functions are available as replacements for existing C librarymemory operation functions. To use these you must include \fImpatrol.h\fPbefore all other header files, although on UNIX and Windows platforms (andAmigaOS when using \fBgcc\fP) they will be used anyway, albeit with slightlyless tracing information:.TP\fBmemset\fPWrites \fIsize\fP bytes of value \fIbyte\fP to the memory location beginning at\fIptr\fP and returns \fIptr\fP. If \fIsize\fP is \fB0\fP then no bytes willbe written. If the operation would affect an existing memory allocation in theheap but would straddle that allocation's boundaries then an error message willbe generated in the log file and no bytes will be written..TP\fBbzero\fPWrites \fIsize\fP zero bytes to the memory location beginning at \fIptr\fP. If\fIsize\fP is \fB0\fP then no bytes will be written. If the operation wouldaffect an existing memory allocation in the heap but would straddle thatallocation's boundaries then an error message will be generated in the log fileand no bytes will be written. This function is available for backwardscompatibility with older C libraries and should not be used in new code..TP\fBmemccpy\fPCopies \fIsize\fP bytes from \fIsrc\fP to \fIdest\fP and returns \fBNULL\fP, orcopies the number of bytes up to and including the first occurrence of\fIbyte\fP if \fIbyte\fP exists within the specified range and returns a pointerto the first byte after \fIbyte\fP. If \fIsize\fP is \fB0\fP or \fIsrc\fP isthe same as \fIdest\fP then no bytes will be copied. The source and destinationranges should not overlap, otherwise a warning will be written to the log file.If the operation would affect an existing memory allocation in the heap butwould straddle that allocation's boundaries then an error message will begenerated in the log file and no bytes will be copied..TP\fBmemcpy\fPCopies \fIsize\fP bytes from \fIsrc\fP to \fIdest\fP and returns \fIdest\fP. If\fIsize\fP is \fB0\fP or \fIsrc\fP is the same as \fIdest\fP then no bytes willbe copied. The source and destination ranges should not overlap, otherwise awarning will be written to the log file. If the operation would affect anexisting memory allocation in the heap but would straddle that allocation'sboundaries then an error message will be generated in the log file and no byteswill be copied..TP\fBmemmove\fPCopies \fIsize\fP bytes from \fIsrc\fP to \fIdest\fP and returns \fIdest\fP. If\fIsize\fP is \fB0\fP or \fIsrc\fP is the same as \fIdest\fP then no bytes willbe copied. If the operation would affect an existing memory allocation in theheap but would straddle that allocation's boundaries then an error message willbe generated in the log file and no bytes will be copied..TP\fBbcopy\fPCopies \fIsize\fP bytes from \fIsrc\fP to \fIdest\fP. If \fIsize\fP is \fB0\fPor \fIsrc\fP is the same as \fIdest\fP then no bytes will be copied. If theoperation would affect an existing memory allocation in the heap but wouldstraddle that allocation's boundaries then an error message will be generated inthe log file and no bytes will be copied. This function is available forbackwards compatibility with older C libraries and should not be used in newcode..TP\fBmemcmp\fPCompares \fIsize\fP bytes from \fIptr1\fP and \fIptr2\fP and returns \fB0\fP ifall of the bytes are identical, or returns the byte difference of the firstdiffering bytes. If \fIsize\fP is \fB0\fP or \fIptr1\fP is the same as\fIptr2\fP then no bytes will be compared. If the operation would read from anexisting memory allocation in the heap but would straddle that allocation'sboundaries then an error message will be generated in the log file and no byteswill be compared..TP\fBbcmp\fPCompares \fIsize\fP bytes from \fIptr1\fP and \fIptr2\fP and returns \fB0\fP ifall of the bytes are identical, or returns the byte difference of the firstdiffering bytes. If \fIsize\fP is \fB0\fP or \fIptr1\fP is the same as\fIptr2\fP then no bytes will be compared. If the operation would read from anexisting memory allocation in the heap but would straddle that allocation'sboundaries then an error message will be generated in the log file and no byteswill be compared. This function is available for backwards compatibility witholder C libraries and should not be used in new code..TP\fBmemchr\fP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -