From Seo Wiki - Search Engine Optimization and Programming Languages
|This article is an orphan, as few or no other articles link to it. Please introduce links to this page from related articles; suggestions are available. (February 2009)|
|This article may need to be wikified to meet Wikipedia's quality standards. Please help by adding relevant internal links, or by improving the article's layout. (December 2008)|
| This article does not cite any references or sources.
Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (December 2008)
|This article may be too technical for most readers to understand. Please improve this article to make it accessible to non-experts, without removing the technical details. (August 2009)|
The brk or sbrk subroutine changes data segment space allocation. Standard C Library (libc.a)
The brk and sbrk subroutines dynamically change the amount of space allocated for the data segment of the calling process. (For information about segments, see the exec subroutine. For information about the maximum amount of space that can be allocated, see the ulimit and getrlimit subroutines.)
The change is made by resetting the break value of the process, which determines the maximum space that can be allocated. The break value is the address of the first location beyond the current end of the data region. The amount of available space increases as the break value increases. The available space is initialized to a value of 0 at the time it is used. The break value can be automatically rounded up to a size appropriate for the memory management architecture.
The brk subroutine sets the break value to the value of the EndDataSegment parameter and changes the amount of available space accordingly.
The sbrk subroutine adds to the break value the number of bytes contained in the Increment parameter and changes the amount of available space accordingly. The Increment parameter can be a negative number, in which case the amount of available space is decreased.
- EndDataSegment Specifies the effective address of the maximum available data.
- Increment Specifies any integer.
- Return Values
Upon successful completion, the brk subroutine returns a value of 0, and the sbrk subroutine returns the old break value. If either subroutine is unsuccessful, a value of -1 is returned and the errno global variable is set to indicate the error.
- Error codes
The brk subroutine and the sbrk subroutine are unsuccessful and the allocated space remains unchanged if one or more of the following are true:
- ENOMEM The requested change allocates more space than is allowed by a system-imposed maximum. (For information on the system-imposed maximum on memory space, see the ulimit system call.)
- ENOMEM The requested change sets the break value to a value greater than or equal to the start address of any attached shared-memory segment. (For information on shared memory operations, see the shmat subroutine.)
#include <unistd .h> int brk ( EndDataSegment) char *EndDataSegment; void *sbrk ( Increment) intptr_t Increment;