|
|
1.1 ! root 1: .ds ZZ DEVELOPMENT PACKAGE ! 2: .TH ALLOC 3R "630 MTG" ! 3: .XE "alloc()" ! 4: .XE "lalloc()" ! 5: .XE "allocown()" ! 6: .XE "free()" ! 7: .SH NAME ! 8: alloc, lalloc, free, allocown \- memory allocation ! 9: .SH SYNOPSIS ! 10: .B #include <dmd.h> ! 11: .br ! 12: .B char \(**alloc (nbytes) ! 13: .PP ! 14: .B char \(**lalloc (lnbytes) ! 15: .PP ! 16: .B void free (s) ! 17: .PP ! 18: .B void allocown (s, p) ! 19: .sp ! 20: .B unsigned nbytes; ! 21: .br ! 22: .B unsigned long lnbytes; ! 23: .br ! 24: .B Proc \(**p ! 25: .br ! 26: .B char \(**s; ! 27: .SH DESCRIPTION ! 28: The ! 29: .I alloc ! 30: function ! 31: is equivalent to the standard C function ! 32: .IR malloc (3C). ! 33: It either returns a pointer to a block of ! 34: \f2nbytes\f1, ! 35: contiguous bytes of storage ! 36: or a 0 (\s-1NULL\s+1) if there is no available memory. ! 37: The storage is aligned on 4-byte boundaries. ! 38: Unlike ! 39: .IR malloc , ! 40: \f2alloc\f1, ! 41: clears the storage to zeros. ! 42: .PP ! 43: The ! 44: .I lalloc ! 45: function is identical to ! 46: .I alloc ! 47: except it takes an unsigned long as an argument. ! 48: .PP ! 49: The ! 50: .I free ! 51: function ! 52: frees storage allocated by ! 53: .IR alloc . ! 54: The space is made available for further allocation. ! 55: .PP ! 56: The ! 57: .I allocown ! 58: function ! 59: changes the ownership of memory allocated by ! 60: .IR alloc. ! 61: The argument ! 62: .I s ! 63: is a value previously returned from ! 64: .IR alloc . ! 65: The argument ! 66: .I p ! 67: is the process taking over ownership of the memory. ! 68: If ! 69: .I p ! 70: is zero, the memory belongs to no one, and only an explicit call to ! 71: .I free ! 72: will free it. ! 73: .PP ! 74: The terminal ! 75: automatically frees all memory allocated by a process ! 76: when the process terminates or when ! 77: the window it is running in is deleted. ! 78: If the ownership of allocated memory is changed, it will ! 79: only be freed when the new owner is deleted or when ! 80: .I free ! 81: is called. ! 82: However, it is recommended that a process free its allocated ! 83: memory when the storage is no longer needed so that other ! 84: processes ! 85: will be able to use it. ! 86: .SH EXAMPLE ! 87: The following example shows the use of ! 88: .I alloc ! 89: and ! 90: .I free ! 91: in dynamically allocating memory for a \fIPoint\fR. ! 92: .PP ! 93: .RS 3 ! 94: .ft CM ! 95: .nf ! 96: #include <dmd.h> ! 97: ! 98: main() ! 99: { ! 100: Point *p; ! 101: char *alloc(); ! 102: void free(); ! 103: ! 104: p = (Point *)alloc (sizeof(Point)); ! 105: ! 106: . ! 107: . ! 108: . ! 109: ! 110: free (p); ! 111: } ! 112: .fi ! 113: .ft R ! 114: .RE ! 115: .SH SEE ALSO ! 116: balloc(3R), gcalloc(3R), structures(3R). ! 117: .br ! 118: malloc(3C) in the \f2UNIX System V Programmer's Reference Manual\f1. ! 119: ! 120: ! 121: .SH WARNINGS ! 122: The ! 123: .I alloc ! 124: function accepts an integer as argument; therefore, it can only allocate a ! 125: contiguous block of memory of 64K bytes or less.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.