Changeset d2260ad


Ignore:
Timestamp:
Jul 20, 2021, 9:31:45 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7056f56
Parents:
8bf9448 (diff), 6acd020 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/mubeen_zulfiqar_MMath/allocator.tex

    r8bf9448 rd2260ad  
    350350
    351351\subsection{Alloc Interface}
    352 Why did we need it?
    353 The added benefits.
     352In addition to improve allocator interface both for CFA and our standalone allocator uHeapLmmm in C. We also added a new alloc interface in CFA that increases usability of dynamic memory allocation.
     353This interface helps programmers in three major ways.
     354\begin{itemize}
     355\item
     356Routine Name: alloc interfce frees programmers from remmebring different routine names for different kind of dynamic allocations.
     357\item
     358Parametre Positions: alloc interface frees programmers from remembering parameter postions in call to routines.
     359\item
     360Object Size: alloc interface does not require programmer to mention the object size as CFA allows allocator to determince the object size from returned type of alloc call.
     361\end{itemize}
     362
     363Alloc interface uses polymorphism, backtick routines (FIX ME: cite backtick) and ttype parameters of CFA (FIX ME: cite ttype) to provide a very simple dynamic memory allocation interface to the programmers. The new interfece has just one routine name alloc that can be used to perform a wide range of dynamic allocations. The parameters use backtick functions to provide a similar-to named parameters feature for our alloc interface so that programmers do not have to remember parameter positions in alloc call except the position of dimension (dim) parameter.
     364
     365\subsubsection{Routine: T * alloc( ... )}
     366Call to alloc wihout any parameter returns one object of size of type T allocated dynamically.
     367Only the dimension (dim) parameter for array allocation has the fixed position in the alloc routine. If programmer wants to allocate an array of objects that the required number of members in the array has to be given as the first parameter to the alloc routine.
     368alocc routine accepts six kinds of arguments. Using different combinations of tha parameters, different kind of allocations can be performed. Any combincation of parameters can be used together except `realloc and `resize that should not be used simultanously in one call to routine as it creates ambiguity about whether to reallocate or resize a currently allocated dynamic object. If both `resize and `realloc are used in a call to alloc then the latter one will take effect or unexpected resulted might be produced.
     369
     370\paragraph{Dim}
     371This is the only parameter in the alloc routine that has a fixed-position and it is also the only parameter that does not use a backtick function. It has to be passed at the first position to alloc call in-case of an array allocation of objects of type T.
     372It represents the required number of members in the array allocation as in CFA's aalloc (FIX ME: cite aalloc).
     373This parameter should be of type size_t.
     374
     375Example: int a = alloc( 5 )
     376This call will return a dynamic array of five integers.
     377
     378\paragraph{Align}
     379This parameter is position-free and uses a backtick routine align (`align). The parameter passed with `align should be of type size_t. If the alignment parameter is not a power of two or is less than the default alignment of the allocator (that can be found out using routine libAlign in CFA) then the passed alignment parameter will be rejected and the default alignment will be used.
     380
     381Example: int b = alloc( 5 , 64`align )
     382This call will return a dynamic array of five integers. It will align the allocated object to 64.
     383
     384\paragraph{Fill}
     385This parameter is position-free and uses a backtick routine fill (`fill). In case of realloc, only the extra space after copying the data in the old object will be filled with given parameter.
     386Three types of parameters can be passed using `fill.
     387\begin{itemize}
     388\item
     389char: A char can be passed with `fill to fill the whole dynamic allocation with the given char recursively till the end of required allocation.
     390\item
     391Object of returned type: An object of type of returned type can be passed with `fill to fill the whole dynamic allocation with the given object recursively till the end of required allocation.
     392\item
     393Dynamic object of returned type: A dynamic object of type of returned type can be passed with `fill to fill the dynamic allocation with the given dynamic object. In this case, the allocated memory is not filled recursively till the end of allocation. The filling happen untill the end object passed to `fill or the end of requested allocation reaches.
     394\end{itemize}
     395
     396Example: int b = alloc( 5 , 'a'`fill )
     397This call will return a dynamic array of five integers. It will fill the allocated object with character 'a' recursively till the end of requested allocation size.
     398
     399Example: int b = alloc( 5 , 4`fill )
     400This call will return a dynamic array of five integers. It will fill the allocated object with integer 4 recursively till the end of requested allocation size.
     401
     402Example: int b = alloc( 5 , a`fill ) where a is a pointer of int type
     403This call will return a dynamic array of five integers. It will copy data in a to the returned object non-recursively untill end of a or the newly allocated object is reached.
     404
     405\paragraph{Resize}
     406This parameter is position-free and uses a backtick routine resize (`resize). It represents the old dynamic object (oaddr) that the programmer wants to
     407\begin{itemize}
     408\item
     409resize to a new size.
     410\item
     411realign to a new alignment
     412\item
     413fill with something.
     414\end{itemize}
     415The data in old dynamic object will not be preserved in the new object. The type of object passed to `resize and the returned type of alloc call can be different.
     416
     417Example: int b = alloc( 5 , a`resize )
     418This call will resize object a to a dynamic array that can contain 5 integers.
     419
     420Example: int b = alloc( 5 , a`resize , 32`align )
     421This call will resize object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32.
     422
     423Example: int b = alloc( 5 , a`resize , 32`align , 2`fill)
     424This call will resize object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32 and will be filled with 2.
     425
     426\paragraph{Realloc}
     427This parameter is position-free and uses a backtick routine realloc (`realloc). It represents the old dynamic object (oaddr) that the programmer wants to
     428\begin{itemize}
     429\item
     430realloc to a new size.
     431\item
     432realign to a new alignment
     433\item
     434fill with something.
     435\end{itemize}
     436The data in old dynamic object will be preserved in the new object. The type of object passed to `realloc and the returned type of alloc call cannot be different.
     437
     438Example: int b = alloc( 5 , a`realloc )
     439This call will realloc object a to a dynamic array that can contain 5 integers.
     440
     441Example: int b = alloc( 5 , a`realloc , 32`align )
     442This call will realloc object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32.
     443
     444Example: int b = alloc( 5 , a`realloc , 32`align , 2`fill)
     445This call will resize object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32. The extra space after copying data of a to the returned object will be filled with 2.
Note: See TracChangeset for help on using the changeset viewer.