Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exec(2)

shmop(2)

ulimit(2)

end(3C)

malloc(3C)

BRK(2)  —  HP-UX

NAME

brk, sbrk − change data segment space allocation

SYNOPSIS

int brk (endds)
char *endds;

char *sbrk (incr)
int incr;

DESCRIPTION

Brk and sbrk are used to change dynamically the amount of space allocated for the calling process’s data segment; see exec(2). 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. The newly allocated space is set to zero.

Brk sets the break value to endds and changes the allocated space accordingly. 

Sbrk adds incr bytes to the break value and changes the allocated space accordingly.  Incr can be negative, in which case the amount of allocated space is decreased. 

ERRORS

Brk and sbrk will fail without making any change in the allocated space if one or more of the following are true:

­[ENOMEM] Such a change would result in more space being allocated than is allowed by a system-imposed maximum (see ulimit(2)).

­[ENOMEM] Such a change would cause a conflict between addresses in the data segment and any attached shared memory segment (see shmop(2)).

DEPENDENCIES

Series 300, 800:
­[ENOMEM] can also be returned if there is insufficient swap space available.

Series 500:
Brk sets the break value to endds. 

Brk and sbrk will also fail without making any change in the allocated space if such a change would move the program break below the beginning of your process’ indirect data area.  Note that it is not possible to release the direct data area with this system call. 

If your process’ indirect data area is paged, then the size of that data area changes in increments of the page size, which is configurable.  Consequently, increasing a paged process data area by one byte may cause it to increase by one page, and decreasing it by one byte may do nothing.  If your process’ data area is not paged, then the size of the process data area changes similarly in increments of 32 bytes. 

WARNINGS

The pointer returned by sbrk is not necessarily word-aligned.  Loading or storing words through this pointer could cause word alignment problems. 

Care should be taken when using either brk(2) or sbrk(2) in conjunction with calls to the malloc(3C) or malloc(3X) library routines. There is only one program data segment from which all three of these routines allocate and deallocate program data memory.  Although it is not recommended practice, it is possible to deallocate program data memory allocated through malloc(3C) with a subsequent call to brk().

RETURN VALUE

Upon successful completion, brk returns a value of 0 and sbrk returns the old break value.  Otherwise, a value of −1 is returned and errno is set to indicate the error. 

AUTHOR

Brk and sbrk were developed by AT&T and HP. 

SEE ALSO

exec(2), shmop(2), ulimit(2), end(3C), malloc(3C). 

Hewlett-Packard Company  —  Version B.1,  May 11, 2021

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026