![]() |
![]() |
![]() |
![]() |
Set the allocation break value
#include <unistd.h> void* sbrk( int increment );
libc
The break value is the address of the first byte of unallocated memory. When a program starts execution, the break value is placed following the code and constant data for the program. As memory is allocated, this pointer advances when there is no free block large enough to satisfy an allocation request. The sbrk() function sets a new break value for the program by adding the value of increment to the current break value.
The variable _amblksiz (defined in <stdlib.h>) contains the default increment. This value may be changed by a program at any time.
A pointer to the start of the new block of memory for success, or -1 if an error occurs (errno is set).
#include <stdio.h> #include <stdlib.h> #define alloc( x, y ) y = sbrk( x ); int main( void ) { void* brk; brk = sbrk( 0x3100 ); printf( "New break value after sbrk( 0x3100 ) \t%p\n", brk ); brk = sbrk( 0x0200 ); printf( "New break value after sbrk( 0x0200 ) \t%p\n", brk ); return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
brk(), calloc(), errno, free(), malloc(), realloc()
![]() |
![]() |
![]() |
![]() |