char *sbrk(int increment);
This system call implements the BSD sbrk function, which allocates more ``bulk'' memory from the system. This system call is typically only used by the high-level malloc memory allocator implemented in the C library.Under raw DOS mode and VCPI, the behavior of sbrk is generally the same as under BSD: the next chunk of memory returned will fall exactly after the previous chunk returned. The increment, and hence the break pointer, doesn't have to be page-aligned.
However, under DPMI 0.9 environments, it is generally impossible to emulate this behavior exactly because the DPMI host does not allow MOSS to request that memory be allocated at a specific address. This deficiency is fixed in DPMI 1.0, but there are still very few hosts that support DPMI 1.0 (neither Windows 3.1 nor Windows 95 do, for example). Therefore, an application using sbrk must be prepared to be given a chunk of memory that does not precisely follow the previously returned chunk.
Furthermore, even under VCPI and raw DOS, the the application calls mmap() to map physical memory, MOSS may map the memory into the program's heap address space and bumps the break pointer appropriately; this is another situation in which consecutive calls to sbrk might not return consecutive memory regions.
Fortunately, the malloc implementation in the BSD C library does not rely on sbrk always returning consecutive chunks; it will still work if the break pointer is thrown off for some reason. However, if this happens, small memory chunks returned by malloc may no longer be naturally aligned, as the BSD man page for malloc says they are. Thus, your application should not depend on this behavior under MOSS. (In general, most malloc packages do not align returned chunks, so depending on this alignment behavior is bad practice anyway.)
- increment
- The number of bytes of memory to allocate.
Returns a pointer to the allocated memory if successful, or (char*)-1 on error, in which case errno indicates the error.