Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/b/brk.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/b/brk.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/b/brk.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/b/brk.html on line 8

brk()

Change the amount of space allocated for the calling process's data segment

Synopsis:

#include <unistd.h>

int brk( void* endds );

Arguments:

endds
A pointer to the new end of the data segment.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.


Note: This function is in libc.a, but not in libc.so (in order to save space).

Description:

The brk() function is used to change dynamically the amount of space allocated for the calling process's data segment (see the exec* functions).

The change is made by resetting the process's break value and allocating the appropriate amount of space. The break value is the address of the first location beyond the end of the data segment. The amount of allocated space increases as the break value increases. Newly allocated space is set to zero. If, however, the same memory space is reallocated to the same process, its contents are undefined.

When a program begins execution using execve(), the break is set at the highest location defined by the program and data storage areas.

You can call getrlimit() to determine the maximum permissible size of the data segment; it isn't possible to set the break beyond the rlim_max value returned from getrlimit(), i.e:

end + rlim.rlim_max

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

ENOMEM
This could mean:
EAGAIN
The total amount of system memory available for private pages is temporarily insufficient. This may occur even though the space requested was less than the maximum data segment size.

Classification:

Legacy Unix

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

Caveats:

Don't use brk() and sbrk() with any other memory functions (such as malloc(), mmap(), and free()). The brk() function assumes that the heap is contiguous; in Neutrino, memory is returned to the system by the heap, causing the heap to become sparse. The Neutrino malloc() function is based on mmap(), and not on brk().

The brk() function has been used in specialized cases where no other memory allocation function provided the same capability. Use mmap() instead because it can be used portably with all other memory allocation functions and with any function that uses other allocation functions.

The value of the argument to brk() is rounded up for alignment with eight-byte boundaries.

See also:

_btext, _edata, _end, _etext, execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), free(), getrlimit(), malloc(), mmap(), sbrk()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/b/brk.html on line 240

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/b/brk.html on line 240