|
|
1.1 root 1: .\" Copyright (c) 1985 Regents of the University of California.
2: .\" All rights reserved. The Berkeley software License Agreement
3: .\" specifies the terms and conditions for redistribution.
4: .\"
5: .\" @(#)malloc.3f 6.1 (Berkeley) 5/15/85
6: .\"
7: .TH MALLOC 3F "May 15, 1985"
8: .UC 6
9: .SH NAME
10: malloc, free, falloc \- memory allocator
11: .SH SYNOPSIS
12: .nf
13: .B subroutine malloc (size, addr)
14: .B integer size, addr
15: .PP
16: .B subroutine free (addr)
17: .B integer addr
18: .PP
19: .B
20: subroutine falloc (nelem, elsize, clean, basevec, addr, offset)
21: .B
22: integer nelem, elsize, clean, addr, offset
23: .fi
24: .SH DESCRIPTION
25: .IR Malloc , \ falloc
26: and
27: .I free
28: provide a general-purpose memory allocation package.
29: .I Malloc
30: returns in
31: .I addr
32: the address of a block of at least
33: .I size
34: bytes beginning on an even-byte boundary.
35: .PP
36: .I Falloc
37: allocates space for an array of
38: .I nelem
39: elements of size
40: .I elsize
41: and returns the address of the block in
42: .I addr.
43: It zeros the block if
44: .I clean
45: is 1.
46: It returns in
47: .I offset
48: an index such that the storage may be addressed as
49: .I basevec(offset+1) ... basevec(offset+nelem).
50: .I Falloc
51: gets extra bytes so that after address arithmetic,
52: all the objects so addressed are within the block.
53: .PP
54: The argument to
55: .I free
56: is the address of a block previously allocated by
57: .I malloc
58: or
59: .IR falloc ;
60: this space is made available for further allocation,
61: but its contents are left undisturbed.
62: To free blocks allocated by
63: .I falloc,
64: use
65: .I addr
66: in calls to
67: .I free,
68: do not use
69: .I basevec(offset+1).
70: .PP
71: Needless to say, grave disorder will result if the space assigned by
72: .IR malloc or falloc
73: is overrun or if some random number is handed to
74: .IR free .
75: .SH DIAGNOSTICS
76: .I Malloc
77: and
78: .I falloc
79: set
80: .I addr
81: to 0 if there is no available memory or if the arena
82: has been detectably corrupted by storing outside the bounds of a block.
83: .PP
84: The following example shows how to obtain memory and use it within a
85: subprogram:
86: .nf
87:
88: integer addr, work(1), offset
89: ...
90: call falloc ( n, 4, 0, work, addr, offset )
91: do 10 i = 1, n
92: work(offset+i) = ...
93: 10 continue
94: .fi
95: .PP
96: The next example reads in dimension information,
97: allocates space for two arrays and two vectors,
98: and calls subroutine
99: .I doit
100: to do the computations:
101: .nf
102:
103: integer addr, dummy(1), offs
104: read *, k, l, m
105: indm1 = 1
106: indm2 = indm1 + k*l
107: indm3 = indm2 + l*m
108: indsym = indm3 + k*m
109: lsym = n*(n+1)/2
110: indv = indsym + lsym
111: indtot = indv + m
112: call falloc ( indtot, 4, 0, dummy, addr, offs )
113: call doit( dummy(indm1+offs), dummy(indm2+offs),
114: . dummy(indm3+offs), dummy(indsym+offs),
115: . dummy(indv +offs), m, n, lsym )
116: end
117: subroutine doit( arr1, arr2, arr3, vsym, vec, m, n, lsym )
118: real arr1(k,l), arr2(l,m), arr3(k,m), vsym(lsym), v2(m)
119: ...
120: .fi
121: .SH FILES
122: /usr/lib/libU77.a
123: .SH SEE ALSO
124: malloc(3)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.