|Skip Navigation Links|
|Exit Print View|
|Programming Interfaces Guide Oracle Solaris 11.1 Information Library|
Library-level dynamic memory allocation provides an easy-to-use interface to dynamic memory allocation.
The most often used interfaces are:
free returns the memory that is obtained from malloc, calloc, realloc, memalign, or valloc to system memory. Trying to free a block that was not reserved by a dynamic memory allocation interface is an error that can cause a process to crash.
calloc returns a pointer to a block of memory that is initialized to zeros. Memory reserved by calloc can be returned to the system through either watchmalloc or free. The memory is allocated and aligned to contain an array of a specified number of elements of a specified size.
realloc changes the size of the memory block allocated to a process. realloc can be used to increase or reduce the size of an allocated block of memory. realloc is the only way to shrink a memory allocation without causing a problem. The location in memory of the reallocated block might be changed, but the contents up to the point of the allocation size change remain the same.
dbx is an interactive, source-level, command-line debugging tool. You can use it to run a program in a controlled manner and to inspect the state of a stopped program. dbx gives you complete control of the dynamic execution of a program, including collecting performance and memory usage data, monitoring memory access, and detecting memory leaks. dbxtool provides a graphical user interface for dbx. See Oracle Solaris Studio 12.3: Debugging a Program With dbx for detailed information.
The Run Time Checking (RTC) tool in the Oracle Solaris Studio software lets you automatically detect runtime errors, such as memory access errors and memory leak, in a native code application during the development phase. It also lets you monitor memory usage. You cannot use runtime checking on Java code. See Chapter 9, Using Runtime Checking, in Oracle Solaris Studio 12.3: Debugging a Program With dbx for details on using the RTC facility.
You can also use the advanced development tool Memory Error Discovery Tool (Discover) for detecting memory access error. See the Oracle Solaris Studio 12.3 Discover and Uncover User's Guide for detailed information.
Oracle Solaris Studio is available on as a package to download and install on the Oracle Solaris 11 OS. For more information, see the Oracle Solaris Studio website.
This section discusses additional memory control interfaces.
sysconf(3C) returns system dependent sizes of memory pages and applications should use getpagesizes(3C) to find out which memory pages are available to a running process. For portability, applications should not embed any constants that specify the size of a page. Note that varying page sizes are not unusual, even among implementations of the same instruction set.
mprotect(2) assigns the specified protection to all pages in the specified address range. The protection cannot exceed the permissions that are allowed on the underlying object.
A break is the greatest valid data address in the process image that is not in the stack. When a program starts executing, the break value is normally set by execve(2) to the greatest address defined by the program and its data storage.
Use brk(2) to set the break to a greater address. You can also use sbrk(2) to add an increment of storage to the data segment of a process. You can get the maximum possible size of the data segment by a call to getrlimit(2).
caddr_t brk(caddr_t addr); caddr_t sbrk(intptr_t incr);