alloca(3) Library Functions Manual alloca(3) NAZWA alloca - przydzielanie pamieci, ktora jest automatycznie zwalniana BIBLIOTEKA Standardowa biblioteka C (libc, -lc) SKLADNIA #include void *alloca(size_t rozmiar); OPIS Funkcja alloca() przydziela rozmiar bajtow pamieci na ramce stosu procedury, z ktorej zostala wywolana. Ta tymczasowa przestrzen jest automatycznie zwalniana po powrocie funkcji, ktora wywoluje alloca() do miejsca wywolania. WARTOSC ZWRACANA Funkcja alloca() zwraca wskaznik do poczatku przydzielonej pamieci. Gdy przydzielenie pamieci spowoduje przepelnienie stosu, zachowanie programu nie jest okreslone. ATRYBUTY Informacje o pojeciach uzywanych w tym rozdziale mozna znalezc w podreczniku attributes(7). +---------------------------+--------------------------+---------------+ |Interfejs | Atrybut | Wartosc | +---------------------------+--------------------------+---------------+ |alloca() | Bezpieczenstwo watkowe | MT-bezpieczne | +---------------------------+--------------------------+---------------+ STANDARDY None. HISTORIA PWB, 32V. UWAGI The alloca() function is machine- and compiler-dependent. Because it allocates from the stack, it's faster than malloc(3) and free(3). In certain cases, it can also simplify memory deallocation in applications that use longjmp(3) or siglongjmp(3). Otherwise, its use is discouraged. Poniewaz przestrzen alokowana przez alloca() jest przydzielana z przestrzeni stosu, to przestrzen ta jest automatycznie zwalniana, jesli nastapi przeskoczenie powrotu z funkcji przez wywolanie longjmp(3) lub siglongjmp(3). The space allocated by alloca() is not automatically deallocated if the pointer that refers to it simply goes out of scope. Pamieci przydzielonej przez alloca() nie mozna zwalniac za pomoca free(3)! By necessity, alloca() is a compiler built-in, also known as __builtin_alloca(). By default, modern compilers automatically translate all uses of alloca() into the built-in, but this is forbidden if standards conformance is requested (-ansi, -std=c*), in which case is required, lest a symbol dependency be emitted. The fact that alloca() is a built-in means it is impossible to take its address or to change its behavior by linking with a different library. Variable length arrays (VLAs) are part of the C99 standard, optional since C11, and can be used for a similar purpose. However, they do not port to standard C++, and, being variables, live in their block scope and don't have an allocator-like interface, making them unfit for implementing functionality like strdupa(3). USTERKI Due to the nature of the stack, it is impossible to check if the allocation would overflow the space available, and, hence, neither is indicating an error. (However, the program is likely to receive a SIGSEGV signal if it attempts to access unavailable space.) W wielu systemach alloca() nie moze byc uzywana w obrebie listy argumentow w wywolaniu funkcji, gdyz zarezerwowana przez alloca() przestrzen stosu znalazlaby sie w srodku przestrzeni stosu przeznaczonej na argumenty funkcji. ZOBACZ TAKZE brk(2), longjmp(3), malloc(3) TLUMACZENIE Autorami polskiego tlumaczenia niniejszej strony podrecznika sa: Adam Byrtek , Andrzej Krzysztofowicz , Robert Luberda i Michal Kulach Niniejsze tlumaczenie jest wolna dokumentacja. Blizsze informacje o warunkach licencji mozna uzyskac zapoznajac sie z GNU General Public License w wersji 3 lub nowszej. Nie przyjmuje sie ZADNEJ ODPOWIEDZIALNOSCI. Bledy w tlumaczeniu strony podrecznika prosimy zglaszac na adres listy dyskusyjnej . Linux man-pages 6.06 31 pazdziernika 2023 r. alloca(3)