4.4BSD/usr/share/man/cat3f/malloc.0

Compare this file to the similar file:
Show the results in this format:

F>=1  .if 3F<=8 .    if 3F>1 .if 3F<6 .ds an-extra3 "BSD Program-



MALLOC(3F)             BSD Reference Manual            MALLOC(3F)

mer's Manual
NNAAMMEE
       malloc, free, falloc - memory allocator

SSYYNNOOPPSSIISS
       ssuubbrroouuttiinnee mmaalllloocc ((ssiizzee,, aaddddrr))
       iinntteeggeerr ssiizzee,, aaddddrr

       ssuubbrroouuttiinnee ffrreeee ((aaddddrr))
       iinntteeggeerr aaddddrr

       ssuubbrroouuttiinnee ffaalllloocc ((nneelleemm,, eellssiizzee,, cclleeaann,, bbaasseevveecc,, aaddddrr,, ooffffsseett))
       iinntteeggeerr nneelleemm,, eellssiizzee,, cclleeaann,, aaddddrr,, ooffffsseett

DDEESSCCRRIIPPTTIIOONN
       _M_a_l_l_o_c, _f_a_l_l_o_c and _f_r_e_e provide a  general-purpose  memory
       allocation package.  _M_a_l_l_o_c returns in _a_d_d_r the address of
       a block of at least _s_i_z_e bytes beginning on  an  even-byte
       boundary.

       _F_a_l_l_o_c  allocates  space for an array of _n_e_l_e_m elements of
       size _e_l_s_i_z_e and returns the address of the block in  _a_d_d_r_.
       It zeros the block if _c_l_e_a_n is 1.  It returns in _o_f_f_s_e_t an
       index  such  that  the  storage  may   be   addressed   as
       _b_a_s_e_v_e_c_(_o_f_f_s_e_t_+_1_)  _._._. _b_a_s_e_v_e_c_(_o_f_f_s_e_t_+_n_e_l_e_m_)_.  _F_a_l_l_o_c gets
       extra bytes so that  after  address  arithmetic,  all  the
       objects so addressed are within the block.

       The  argument to _f_r_e_e is the address of a block previously
       allocated by _m_a_l_l_o_c or _f_a_l_l_o_c; this space is  made  avail-
       able  for  further  allocation,  but its contents are left
       undisturbed.  To free blocks allocated by _f_a_l_l_o_c_, use _a_d_d_r
       in calls to _f_r_e_e_, do not use _b_a_s_e_v_e_c_(_o_f_f_s_e_t_+_1_)_.

       Needless  to  say, grave disorder will result if the space
       assigned by _m_a_l_l_o_cor_f_a_l_l_o_c is overrun or  if  some  random
       number is handed to _f_r_e_e.

DDIIAAGGNNOOSSTTIICCSS
       _M_a_l_l_o_c  and  _f_a_l_l_o_c set _a_d_d_r to 0 if there is no available
       memory or if the arena has been  detectably  corrupted  by
       storing outside the bounds of a block.

       The  following  example shows how to obtain memory and use
       it within a subprogram:

             integer addr, work(1), offset
                ...
             call falloc ( n, 4, 0, work, addr, offset )
             do 10 i = 1, n
             work(offset+i) = ...



4.3 Berkeley Distribution  June 5, 1993                         1








MALLOC(3F)             BSD Reference Manual            MALLOC(3F)


       10    continue

       The next example reads in dimension information, allocates
       space for two arrays and two vectors, and calls subroutine
       _d_o_i_t to do the computations:

             integer addr, dummy(1), offs
             read *, k, l, m
             indm1   = 1
             indm2   = indm1 + k*l
             indm3   = indm2 + l*m
             indsym  = indm3 + k*m
             lsym = n*(n+1)/2
             indv  = indsym + lsym
             indtot = indv + m
             call falloc ( indtot, 4, 0, dummy, addr, offs )
             call doit( dummy(indm1+offs), dummy(indm2+offs),
            .           dummy(indm3+offs), dummy(indsym+offs),
            .           dummy(indv +offs), m, n, lsym )
             end
             subroutine doit( arr1, arr2, arr3, vsym, vec, m, n, lsym )
             real arr1(k,l), arr2(l,m), arr3(k,m), vsym(lsym), v2(m)
                ...

FFIILLEESS
       /usr/lib/libU77.a

SSEEEE AALLSSOO
       malloc(3)

























4.3 Berkeley Distribution  June 5, 1993                         2