source: trunk/libs/newlib/src/newlib/libc/machine/powerpc/vec_malloc.c @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 3.6 KB
Line 
1/*
2FUNCTION
3<<vec_malloc>>, <<vec_realloc>>, <<vec_free>>---manage vector memory
4
5INDEX
6        vec_malloc
7INDEX
8        vec_realloc
9INDEX
10        vec_free
11INDEX
12        _vec_malloc_r
13INDEX
14        _vec_realloc_r
15INDEX
16        _vec_free_r
17
18SYNOPSIS
19        #include <stdlib.h>
20        void *vec_malloc(size_t <[nbytes]>);
21        void *vec_realloc(void *<[aptr]>, size_t <[nbytes]>);
22        void vec_free(void *<[aptr]>);
23
24
25        void *_vec_malloc_r(void *<[reent]>, size_t <[nbytes]>);
26        void *_vec_realloc_r(void *<[reent]>,
27                         void *<[aptr]>, size_t <[nbytes]>);
28        void _vec_free_r(void *<[reent]>, void *<[aptr]>);
29
30DESCRIPTION
31These functions manage a pool of system memory that is 16-byte aligned..
32
33Use <<vec_malloc>> to request allocation of an object with at least
34<[nbytes]> bytes of storage available and is 16-byte aligned.  If the space is
35available, <<vec_malloc>> returns a pointer to a newly allocated block as its result.
36
37If you already have a block of storage allocated by <<vec_malloc>>, but
38you no longer need all the space allocated to it, you can make it
39smaller by calling <<vec_realloc>> with both the object pointer and the
40new desired size as arguments.  <<vec_realloc>> guarantees that the
41contents of the smaller object match the beginning of the original object.
42
43Similarly, if you need more space for an object, use <<vec_realloc>> to
44request the larger size; again, <<vec_realloc>> guarantees that the
45beginning of the new, larger object matches the contents of the
46original object.
47
48When you no longer need an object originally allocated by <<vec_malloc>>
49or <<vec_realloc>> (or the related function <<vec_calloc>>), return it to the
50memory storage pool by calling <<vec_free>> with the address of the object
51as the argument.  You can also use <<vec_realloc>> for this purpose by
52calling it with <<0>> as the <[nbytes]> argument.
53
54The alternate functions <<_vec_malloc_r>>, <<_vec_realloc_r>>, <<_vec_free_r>>,
55are reentrant versions.  The extra argument <[reent]> is a pointer to a reentrancy
56structure.
57
58If you have multiple threads of execution which may call any of these
59routines, or if any of these routines may be called reentrantly, then
60you must provide implementations of the <<__vec_malloc_lock>> and
61<<__vec_malloc_unlock>> functions for your system.  See the documentation
62for those functions.
63
64These functions operate by calling the function <<_sbrk_r>> or
65<<sbrk>>, which allocates space.  You may need to provide one of these
66functions for your system.  <<_sbrk_r>> is called with a positive
67value to allocate more space, and with a negative value to release
68previously allocated space if it is no longer required.
69@xref{Stubs}.
70
71RETURNS
72<<vec_malloc>> returns a pointer to the newly allocated space, if
73successful; otherwise it returns <<NULL>>.  If your application needs
74to generate empty objects, you may use <<vec_malloc(0)>> for this purpose.
75
76<<vec_realloc>> returns a pointer to the new block of memory, or <<NULL>>
77if a new block could not be allocated.  <<NULL>> is also the result
78when you use `<<vec_realloc(<[aptr]>,0)>>' (which has the same effect as
79`<<vec_free(<[aptr]>)>>').  You should always check the result of
80<<vec_realloc>>; successful vec_reallocation is not guaranteed even when
81you request a smaller object.
82
83<<vec_free>> does not return a result.
84
85PORTABILITY
86<<vec_malloc>>, <<vec_realloc>>, and <<vec_free>> are all extensions
87specified in the AltiVec Programming Interface Manual.
88
89Supporting OS subroutines required: <<sbrk>>.  */
90
91#include <_ansi.h>
92#include <reent.h>
93#include <stdlib.h>
94#include <malloc.h>
95
96#ifndef _REENT_ONLY
97
98void *
99vec_malloc (size_t nbytes)              /* get a block */
100{
101  return _memalign_r (_REENT, 16, nbytes);
102}
103
104#endif
105
Note: See TracBrowser for help on using the repository browser.