📄 vec_malloc.c
字号:
/*FUNCTION<<vec_malloc>>, <<vec_realloc>>, <<vec_free>>---manage vector memoryINDEX vec_mallocINDEX vec_reallocINDEX vec_freeINDEX _vec_malloc_rINDEX _vec_realloc_rINDEX _vec_free_rANSI_SYNOPSIS #include <stdlib.h> void *vec_malloc(size_t <[nbytes]>); void *vec_realloc(void *<[aptr]>, size_t <[nbytes]>); void vec_free(void *<[aptr]>); void *_vec_malloc_r(void *<[reent]>, size_t <[nbytes]>); void *_vec_realloc_r(void *<[reent]>, void *<[aptr]>, size_t <[nbytes]>); void _vec_free_r(void *<[reent]>, void *<[aptr]>);TRAD_SYNOPSIS #include <stdlib.h> char *vec_malloc(<[nbytes]>) size_t <[nbytes]>; char *vec_realloc(<[aptr]>, <[nbytes]>) char *<[aptr]>; size_t <[nbytes]>; void vec_free(<[aptr]>) char *<[aptr]>; char *_vec_malloc_r(<[reent]>,<[nbytes]>) char *<[reent]>; size_t <[nbytes]>; char *_vec_realloc_r(<[reent]>, <[aptr]>, <[nbytes]>) char *<[reent]>; char *<[aptr]>; size_t <[nbytes]>; void _vec_free_r(<[reent]>, <[aptr]>) char *<[reent]>; char *<[aptr]>;DESCRIPTIONThese functions manage a pool of system memory that is 16-byte aligned..Use <<vec_malloc>> to request allocation of an object with at least<[nbytes]> bytes of storage available and is 16-byte aligned. If the space is available, <<vec_malloc>> returns a pointer to a newly allocated block as its result.If you already have a block of storage allocated by <<vec_malloc>>, butyou no longer need all the space allocated to it, you can make itsmaller by calling <<vec_realloc>> with both the object pointer and thenew desired size as arguments. <<vec_realloc>> guarantees that thecontents of the smaller object match the beginning of the original object.Similarly, if you need more space for an object, use <<vec_realloc>> torequest the larger size; again, <<vec_realloc>> guarantees that thebeginning of the new, larger object matches the contents of theoriginal object.When you no longer need an object originally allocated by <<vec_malloc>>or <<vec_realloc>> (or the related function <<vec_calloc>>), return it to thememory storage pool by calling <<vec_free>> with the address of the objectas the argument. You can also use <<vec_realloc>> for this purpose bycalling it with <<0>> as the <[nbytes]> argument.The alternate functions <<_vec_malloc_r>>, <<_vec_realloc_r>>, <<_vec_free_r>>,are reentrant versions. The extra argument <[reent]> is a pointer to a reentrancy structure.If you have multiple threads of execution which may call any of theseroutines, or if any of these routines may be called reentrantly, thenyou must provide implementations of the <<__vec_malloc_lock>> and<<__vec_malloc_unlock>> functions for your system. See the documentationfor those functions.These functions operate by calling the function <<_sbrk_r>> or<<sbrk>>, which allocates space. You may need to provide one of thesefunctions for your system. <<_sbrk_r>> is called with a positivevalue to allocate more space, and with a negative value to releasepreviously allocated space if it is no longer required.@xref{Stubs}.RETURNS<<vec_malloc>> returns a pointer to the newly allocated space, ifsuccessful; otherwise it returns <<NULL>>. If your application needsto generate empty objects, you may use <<vec_malloc(0)>> for this purpose.<<vec_realloc>> returns a pointer to the new block of memory, or <<NULL>>if a new block could not be allocated. <<NULL>> is also the resultwhen you use `<<vec_realloc(<[aptr]>,0)>>' (which has the same effect as`<<vec_free(<[aptr]>)>>'). You should always check the result of<<vec_realloc>>; successful vec_reallocation is not guaranteed even whenyou request a smaller object.<<vec_free>> does not return a result.PORTABILITY<<vec_malloc>>, <<vec_realloc>>, and <<vec_free>> are all extensionsspecified in the AltiVec Programming Interface Manual.Supporting OS subroutines required: <<sbrk>>. */#include <_ansi.h>#include <reent.h>#include <stdlib.h>#include <malloc.h>#ifndef _REENT_ONLY_PTR_DEFUN (vec_malloc, (nbytes), size_t nbytes) /* get a block */{ return _memalign_r (_REENT, 16, nbytes);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -