[13] | 1 | .\" Storage management library man page |
---|
| 2 | .TH MEM 3 "16 November 1993" |
---|
| 3 | .SH NAME |
---|
| 4 | mem \- a memory management package |
---|
| 5 | .SH SYNOPSIS |
---|
| 6 | .B #include <memuser.h> |
---|
| 7 | .SH DESCRIPTION |
---|
| 8 | The |
---|
| 9 | .B libmem |
---|
| 10 | library provides a set of routines for allocating storage. Programs |
---|
| 11 | designed to be used with the library should use the |
---|
| 12 | .B -lmem |
---|
| 13 | options to |
---|
| 14 | .B cc |
---|
| 15 | when linking. |
---|
| 16 | .SH "LIST OF FUNCTIONS" |
---|
| 17 | .nf |
---|
| 18 | .ta 3in |
---|
| 19 | \fIName\fP \fIFunction\fP |
---|
| 20 | mem_get_block Allocate a block of memory |
---|
| 21 | mem_free_block Free a block of memory |
---|
| 22 | mem_resize_block Resize a block of memory |
---|
| 23 | mem_copy Copy a block of memory |
---|
| 24 | mem_zero Initialize a block of memory to all zeros |
---|
| 25 | mem_allocation Get total memory allocation |
---|
| 26 | mem_new_rec_mgr Create a record manager |
---|
| 27 | mem_free_rec_mgr Destroy a record manager |
---|
| 28 | mem_new_rec Get a record from a record manager |
---|
| 29 | mem_free_rec Return a record to a record manager |
---|
| 30 | .fi |
---|
| 31 | .SH "OVERVIEW" |
---|
| 32 | The library includes routines for handling blocks of memory and for |
---|
| 33 | dealing with fixed size records. The block manipulation routines use |
---|
| 34 | a binary buddy scheme, so fragmentation generally is not a problem. |
---|
| 35 | The record manager routines are designed for handling many small, |
---|
| 36 | fixed size records. There is essentially no storage overhead when |
---|
| 37 | using these routines, and allocation and deallocation are particularly |
---|
| 38 | fast. |
---|
| 39 | .SH "DETAILED DESCRIPTION" |
---|
| 40 | .B pointer |
---|
| 41 | .br |
---|
| 42 | .B mem_get_block(size) |
---|
| 43 | .br |
---|
| 44 | .B long size; |
---|
| 45 | .in +4 |
---|
| 46 | Allocate a block of storage |
---|
| 47 | .B size |
---|
| 48 | bytes long. The type |
---|
| 49 | .B pointer |
---|
| 50 | is defined to be either a character pointer or a void pointer, |
---|
| 51 | depending on whether the C compiler is ANSI-standard. |
---|
| 52 | .LP |
---|
| 53 | .B void |
---|
| 54 | .br |
---|
| 55 | .B mem_free_block(p) |
---|
| 56 | .br |
---|
| 57 | .B pointer p; |
---|
| 58 | .in +4 |
---|
| 59 | Free the block of storage pointed to by \fBp\fR. |
---|
| 60 | .LP |
---|
| 61 | .B pointer |
---|
| 62 | .br |
---|
| 63 | .B mem_resize_block(p, size) |
---|
| 64 | .br |
---|
| 65 | .B pointer p; |
---|
| 66 | .br |
---|
| 67 | .B long size; |
---|
| 68 | .in +4 |
---|
| 69 | Try to resize the block of memory pointed to by |
---|
| 70 | .B p |
---|
| 71 | to be |
---|
| 72 | .B size |
---|
| 73 | bytes long. If this is not possible, a new block is allocated and the |
---|
| 74 | contents of the old block are copied. A pointer to the expanded block |
---|
| 75 | is returned. |
---|
| 76 | .LP |
---|
| 77 | .B void |
---|
| 78 | .br |
---|
| 79 | .B mem_copy(p, q, size) |
---|
| 80 | .br |
---|
| 81 | .B pointer p; |
---|
| 82 | .br |
---|
| 83 | .B pointer q; |
---|
| 84 | .br |
---|
| 85 | .B long size; |
---|
| 86 | .in +4 |
---|
| 87 | Copy |
---|
| 88 | .B size |
---|
| 89 | bytes from the location given by |
---|
| 90 | .B q |
---|
| 91 | to the location give by \fBp\fR. |
---|
| 92 | .LP |
---|
| 93 | .LP |
---|
| 94 | .B void |
---|
| 95 | .br |
---|
| 96 | .B mem_zero(p, size) |
---|
| 97 | .br |
---|
| 98 | .B pointer p; |
---|
| 99 | .br |
---|
| 100 | .B long size; |
---|
| 101 | .in +4 |
---|
| 102 | Fill |
---|
| 103 | .B size |
---|
| 104 | bytes at the location given by |
---|
| 105 | .B p |
---|
| 106 | with zero. |
---|
| 107 | .LP |
---|
| 108 | .B long |
---|
| 109 | .br |
---|
| 110 | .B mem_allocation() |
---|
| 111 | .in +4 |
---|
| 112 | Returns the total memory allocation in bytes. |
---|
| 113 | .LP |
---|
| 114 | .B rec_mgr |
---|
| 115 | .br |
---|
| 116 | .B mem_new_rec_mgr(size) |
---|
| 117 | .br |
---|
| 118 | .B int size; |
---|
| 119 | .in +4 |
---|
| 120 | Returns a new record manager for handling record of |
---|
| 121 | .B size |
---|
| 122 | bytes. The size is limited to approximately 4K, but is really |
---|
| 123 | intended to be smaller. |
---|
| 124 | .LP |
---|
| 125 | .B void |
---|
| 126 | .br |
---|
| 127 | .B mem_free_rec_mgr(m) |
---|
| 128 | .br |
---|
| 129 | .B rec_mgr m; |
---|
| 130 | .in +4 |
---|
| 131 | Free the record manager given by |
---|
| 132 | .B m |
---|
| 133 | and all of its associated storage. |
---|
| 134 | .LP |
---|
| 135 | .B pointer |
---|
| 136 | .br |
---|
| 137 | .B mem_new_rec(m) |
---|
| 138 | .br |
---|
| 139 | .B rec_mgr m; |
---|
| 140 | .in +4 |
---|
| 141 | Return a pointer to a new record. |
---|
| 142 | .LP |
---|
| 143 | .B void |
---|
| 144 | .br |
---|
| 145 | .B mem_free_rec(m, p) |
---|
| 146 | .br |
---|
| 147 | .B rec_mgr m; |
---|
| 148 | .br |
---|
| 149 | .B pointer p; |
---|
| 150 | .in +4 |
---|
| 151 | Return the record pointed to by |
---|
| 152 | .B p |
---|
| 153 | to the record manager \fBm\fR. |
---|
| 154 | .SH "PORTABILITY NOTES" |
---|
| 155 | The library is fairly UNIX specific; it calls |
---|
| 156 | .B sbrk |
---|
| 157 | directly. If you don't have something similar, you may have to |
---|
| 158 | rewrite parts of it. The storage management routines need to be able |
---|
| 159 | to move and clear blocks of memory whose size is given by a long. You |
---|
| 160 | may have to fiddle with these, especially if you have a machine where |
---|
| 161 | int and long are different. If you encounter portability problems, |
---|
| 162 | let me know; maybe the next release will be able to accommodate your |
---|
| 163 | machine. For non-UNIX people, or if you are using malloc elsewhere |
---|
| 164 | and it is unhappy about other routines calling sbrk, you can try |
---|
| 165 | defining the symbol USE_MALLOC_FREE in memint.h. It turns calls to |
---|
| 166 | the memory management library routines into calls to malloc, free, and |
---|
| 167 | cousins. This has not been tested extensively. |
---|
| 168 | .SH BUGS |
---|
| 169 | It's a feature. |
---|
| 170 | .SH AUTHOR |
---|
| 171 | David E. Long |
---|
| 172 | .br |
---|
| 173 | long@research.att.com |
---|
| 174 | |
---|