1MALLOC(3F) MALLOC(3F)
2
3
4
6 malloc, free, falloc - memory allocator
7
9 subroutine malloc (size, addr)
10 integer size, addr
11
12 subroutine free (addr)
13 integer addr
14
15 subroutine falloc (nelem, elsize, clean, basevec, addr, offset)
16 integer nelem, elsize, clean, addr, offset
17
19 Malloc, falloc and free provide a general-purpose memory allocation
20 package. Malloc returns in addr the address of a block of at least
21 size bytes beginning on an even-byte boundary.
22
23 Falloc allocates space for an array of nelem elements of size elsize
24 and returns the address of the block in addr. It zeros the block if
25 clean is 1. It returns in offset an index such that the storage may be
26 addressed as basevec(offset+1) ... basevec(offset+nelem). Falloc gets
27 extra bytes so that after address arithmetic, all the objects so
28 addressed are within the block.
29
30 The argument to free is the address of a block previously allocated by
31 malloc or falloc; this space is made available for further allocation,
32 but its contents are left undisturbed. To free blocks allocated by
33 falloc, use addr in calls to free, do not use basevec(offset+1).
34
35 Needless to say, grave disorder will result if the space assigned by
36 mallocorfalloc is overrun or if some random number is handed to free.
37
39 Malloc and falloc set addr to 0 if there is no available memory or if
40 the arena has been detectably corrupted by storing outside the bounds
41 of a block.
42
43 The following example shows how to obtain memory and use it within a
44 subprogram:
45
46 integer addr, work(1), offset
47 ...
48 call falloc ( n, 4, 0, work, addr, offset )
49 do 10 i = 1, n
50 work(offset+i) = ...
51 10 continue
52
53 The next example reads in dimension information, allocates space for
54 two arrays and two vectors, and calls subroutine doit to do the compuā
55 tations:
56
57 integer addr, dummy(1), offs
58 read *, k, l, m
59 indm1 = 1
60 indm2 = indm1 + k*l
61 indm3 = indm2 + l*m
62 indsym = indm3 + k*m
63 lsym = n*(n+1)/2
64 indv = indsym + lsym
65 indtot = indv + m
66 call falloc ( indtot, 4, 0, dummy, addr, offs )
67 call doit( dummy(indm1+offs), dummy(indm2+offs),
68 . dummy(indm3+offs), dummy(indsym+offs),
69 . dummy(indv +offs), m, n, lsym )
70 end
71 subroutine doit( arr1, arr2, arr3, vsym, vec, m, n, lsym )
72 real arr1(k,l), arr2(l,m), arr3(k,m), vsym(lsym), v2(m)
73 ...
74
76 /usr/lib/libU77.a
77
79 malloc(3)
80
81
82
834.3 Berkeley Distribution May 15, 1985 MALLOC(3F)