sbrk

From Seo Wiki - Search Engine Optimization and Programming Languages
Jump to navigationJump to search

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.

Parameters
  • 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.)

Syntax

#include <unistd .h>

int brk ( EndDataSegment)
char *EndDataSegment;

void *sbrk ( Increment)
intptr_t Increment;

External links

Template:Unix-stub Template:Unix commands

If you like SEOmastering Site, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...