Ignore:
Timestamp:
Oct 27, 2021, 10:05:59 PM (3 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
a2e4b0c
Parents:
c600df1
Message:

removed errors from thesis and separated background chapter

File:
1 edited

Legend:

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

    rc600df1 r15885de9  
    2424\end{itemize}
    2525
    26 The new features added to uHeapLmmm (incl. @malloc_size@ routine)
     26The new features added to uHeapLmmm (incl. @malloc\_size@ routine)
    2727\CFA alloc interface with examples.
     28
    2829\begin{itemize}
    2930\item
     
    117118We added a few more features and routines to the allocator's C interface that can make the allocator more usable to the programmers. THese features will programmer more control on the dynamic memory allocation.
    118119
    119 \subsubsection void * aalloc( size_t dim, size_t elemSize )
     120\subsubsection void * aalloc( size\_t dim, size\_t elemSize )
    120121aalloc is an extension of malloc. It allows programmer to allocate a dynamic array of objects without calculating the total size of array explicitly. The only alternate of this routine in the other allocators is calloc but calloc also fills the dynamic memory with 0 which makes it slower for a programmer who only wants to dynamically allocate an array of objects without filling it with 0.
    121122\paragraph{Usage}
    122123aalloc takes two parameters.
     124
    123125\begin{itemize}
    124126\item
     
    129131It returns address of dynamic object allocatoed on heap that can contain dim number of objects of the size elemSize. On failure, it returns NULL pointer.
    130132
    131 \subsubsection void * resize( void * oaddr, size_t size )
     133\subsubsection void * resize( void * oaddr, size\_t size )
    132134resize is an extension of relloc. It allows programmer to reuse a cuurently allocated dynamic object with a new size requirement. Its alternate in the other allocators is realloc but relloc also copy the data in old object to the new object which makes it slower for the programmer who only wants to reuse an old dynamic object for a new size requirement but does not want to preserve the data in the old object to the new object.
    133135\paragraph{Usage}
    134136resize takes two parameters.
     137
    135138\begin{itemize}
    136139\item
     
    141144It returns an object that is of the size given but it does not preserve the data in the old object. On failure, it returns NULL pointer.
    142145
    143 \subsubsection void * resize( void * oaddr, size_t nalign, size_t size )
     146\subsubsection void * resize( void * oaddr, size\_t nalign, size\_t size )
    144147This resize is an extension of the above resize (FIX ME: cite above resize). In addition to resizing the size of of an old object, it can also realign the old object to a new alignment requirement.
    145148\paragraph{Usage}
    146149This resize takes three parameters. It takes an additional parameter of nalign as compared to the above resize (FIX ME: cite above resize).
     150
    147151\begin{itemize}
    148152\item
     
    155159It returns an object with the size and alignment given in the parameters. On failure, it returns a NULL pointer.
    156160
    157 \subsubsection void * amemalign( size_t alignment, size_t dim, size_t elemSize )
     161\subsubsection void * amemalign( size\_t alignment, size\_t dim, size\_t elemSize )
    158162amemalign is a hybrid of memalign and aalloc. It allows programmer to allocate an aligned dynamic array of objects without calculating the total size of the array explicitly. It frees the programmer from calculating the total size of the array.
    159163\paragraph{Usage}
    160164amemalign takes three parameters.
     165
    161166\begin{itemize}
    162167\item
     
    169174It returns a dynamic array of objects that has the capacity to contain dim number of objects of the size of elemSize. The returned dynamic array is aligned to the given alignment. On failure, it returns NULL pointer.
    170175
    171 \subsubsection void * cmemalign( size_t alignment, size_t dim, size_t elemSize )
     176\subsubsection void * cmemalign( size\_t alignment, size\_t dim, size\_t elemSize )
    172177cmemalign is a hybrid of amemalign and calloc. It allows programmer to allocate an aligned dynamic array of objects that is 0 filled. The current way to do this in other allocators is to allocate an aligned object with memalign and then fill it with 0 explicitly. This routine provides both features of aligning and 0 filling, implicitly.
    173178\paragraph{Usage}
    174179cmemalign takes three parameters.
     180
    175181\begin{itemize}
    176182\item
     
    183189It returns a dynamic array of objects that has the capacity to contain dim number of objects of the size of elemSize. The returned dynamic array is aligned to the given alignment and is 0 filled. On failure, it returns NULL pointer.
    184190
    185 \subsubsection size_t malloc_alignment( void * addr )
    186 malloc_alignment returns the alignment of a currently allocated dynamic object. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verofying the alignment of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was allocated with the required alignment.
    187 \paragraph{Usage}
    188 malloc_alignment takes one parameters.
     191\subsubsection size\_t malloc\_alignment( void * addr )
     192malloc\_alignment returns the alignment of a currently allocated dynamic object. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verofying the alignment of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was allocated with the required alignment.
     193\paragraph{Usage}
     194malloc\_alignment takes one parameters.
     195
    189196\begin{itemize}
    190197\item
    191198addr: the address of the currently allocated dynamic object.
    192199\end{itemize}
    193 malloc_alignment returns the alignment of the given dynamic object. On failure, it return the value of default alignment of the uHeapLmmm allocator.
    194 
    195 \subsubsection bool malloc_zero_fill( void * addr )
    196 malloc_zero_fill returns whether a currently allocated dynamic object was initially zero filled at the time of allocation. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verifying the zero filled property of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was zero filled at the time of allocation.
    197 \paragraph{Usage}
    198 malloc_zero_fill takes one parameters.
     200malloc\_alignment returns the alignment of the given dynamic object. On failure, it return the value of default alignment of the uHeapLmmm allocator.
     201
     202\subsubsection bool malloc\_zero\_fill( void * addr )
     203malloc\_zero\_fill returns whether a currently allocated dynamic object was initially zero filled at the time of allocation. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verifying the zero filled property of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was zero filled at the time of allocation.
     204\paragraph{Usage}
     205malloc\_zero\_fill takes one parameters.
     206
    199207\begin{itemize}
    200208\item
    201209addr: the address of the currently allocated dynamic object.
    202210\end{itemize}
    203 malloc_zero_fill returns true if the dynamic object was initially zero filled and return false otherwise. On failure, it returns false.
    204 
    205 \subsubsection size_t malloc_size( void * addr )
    206 malloc_size returns the allocation size of a currently allocated dynamic object. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verofying the alignment of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was allocated with the required size. Its current alternate in the other allocators is malloc_usable_size. But, malloc_size is different from malloc_usable_size as malloc_usabe_size returns the total data capacity of dynamic object including the extra space at the end of the dynamic object. On the other hand, malloc_size returns the size that was given to the allocator at the allocation of the dynamic object. This size is updated when an object is realloced, resized, or passed through a similar allocator routine.
    207 \paragraph{Usage}
    208 malloc_size takes one parameters.
     211malloc\_zero\_fill returns true if the dynamic object was initially zero filled and return false otherwise. On failure, it returns false.
     212
     213\subsubsection size\_t malloc\_size( void * addr )
     214malloc\_size returns the allocation size of a currently allocated dynamic object. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verofying the alignment of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was allocated with the required size. Its current alternate in the other allocators is malloc\_usable\_size. But, malloc\_size is different from malloc\_usable\_size as malloc\_usabe\_size returns the total data capacity of dynamic object including the extra space at the end of the dynamic object. On the other hand, malloc\_size returns the size that was given to the allocator at the allocation of the dynamic object. This size is updated when an object is realloced, resized, or passed through a similar allocator routine.
     215\paragraph{Usage}
     216malloc\_size takes one parameters.
     217
    209218\begin{itemize}
    210219\item
    211220addr: the address of the currently allocated dynamic object.
    212221\end{itemize}
    213 malloc_size returns the allocation size of the given dynamic object. On failure, it return zero.
    214 
    215 \subsubsection void * realloc( void * oaddr, size_t nalign, size_t size )
     222malloc\_size returns the allocation size of the given dynamic object. On failure, it return zero.
     223
     224\subsubsection void * realloc( void * oaddr, size\_t nalign, size\_t size )
    216225This realloc is an extension of the default realloc (FIX ME: cite default realloc). In addition to reallocating an old object and preserving the data in old object, it can also realign the old object to a new alignment requirement.
    217226\paragraph{Usage}
    218227This realloc takes three parameters. It takes an additional parameter of nalign as compared to the default realloc.
     228
    219229\begin{itemize}
    220230\item
     
    237247It returns a dynamic object of the size of type T. On failure, it return NULL pointer.
    238248
    239 \subsubsection T * aalloc( size_t dim )
     249\subsubsection T * aalloc( size\_t dim )
    240250This aalloc is a simplified polymorphic form of above aalloc (FIX ME: cite aalloc). It takes one parameter as compared to the above aalloc that takes two parameters.
    241251\paragraph{Usage}
    242252aalloc takes one parameters.
     253
    243254\begin{itemize}
    244255\item
     
    247258It returns a dynamic object that has the capacity to contain dim number of objects, each of the size of type T. On failure, it return NULL pointer.
    248259
    249 \subsubsection T * calloc( size_t dim )
     260\subsubsection T * calloc( size\_t dim )
    250261This calloc is a simplified polymorphic form of defualt calloc (FIX ME: cite calloc). It takes one parameter as compared to the default calloc that takes two parameters.
    251262\paragraph{Usage}
    252263This calloc takes one parameter.
     264
    253265\begin{itemize}
    254266\item
     
    257269It returns a dynamic object that has the capacity to contain dim number of objects, each of the size of type T. On failure, it return NULL pointer.
    258270
    259 \subsubsection T * resize( T * ptr, size_t size )
     271\subsubsection T * resize( T * ptr, size\_t size )
    260272This resize is a simplified polymorphic form of above resize (FIX ME: cite resize with alignment). It takes two parameters as compared to the above resize that takes three parameters. It frees the programmer from explicitly mentioning the alignment of the allocation as CFA provides gives allocator the liberty to get the alignment of the returned type.
    261273\paragraph{Usage}
    262274This resize takes two parameters.
     275
    263276\begin{itemize}
    264277\item
     
    269282It returns a dynamic object of the size given in paramters. The returned object is aligned to the alignemtn of type T. On failure, it return NULL pointer.
    270283
    271 \subsubsection T * realloc( T * ptr, size_t size )
     284\subsubsection T * realloc( T * ptr, size\_t size )
    272285This realloc is a simplified polymorphic form of defualt realloc (FIX ME: cite realloc with align). It takes two parameters as compared to the above realloc that takes three parameters. It frees the programmer from explicitly mentioning the alignment of the allocation as CFA provides gives allocator the liberty to get the alignment of the returned type.
    273286\paragraph{Usage}
    274287This realloc takes two parameters.
     288
    275289\begin{itemize}
    276290\item
     
    281295It returns a dynamic object of the size given in paramters that preserves the data in the given object. The returned object is aligned to the alignemtn of type T. On failure, it return NULL pointer.
    282296
    283 \subsubsection T * memalign( size_t align )
     297\subsubsection T * memalign( size\_t align )
    284298This memalign is a simplified polymorphic form of defualt memalign (FIX ME: cite memalign). It takes one parameters as compared to the default memalign that takes two parameters.
    285299\paragraph{Usage}
    286300memalign takes one parameters.
     301
    287302\begin{itemize}
    288303\item
     
    291306It returns a dynamic object of the size of type T that is aligned to given parameter align. On failure, it return NULL pointer.
    292307
    293 \subsubsection T * amemalign( size_t align, size_t dim )
     308\subsubsection T * amemalign( size\_t align, size\_t dim )
    294309This amemalign is a simplified polymorphic form of above amemalign (FIX ME: cite amemalign). It takes two parameter as compared to the above amemalign that takes three parameters.
    295310\paragraph{Usage}
    296311amemalign takes two parameters.
     312
    297313\begin{itemize}
    298314\item
     
    303319It returns a dynamic object that has the capacity to contain dim number of objects, each of the size of type T. The returned object is aligned to the given parameter align. On failure, it return NULL pointer.
    304320
    305 \subsubsection T * cmemalign( size_t align, size_t dim  )
     321\subsubsection T * cmemalign( size\_t align, size\_t dim  )
    306322This cmemalign is a simplified polymorphic form of above cmemalign (FIX ME: cite cmemalign). It takes two parameter as compared to the above cmemalign that takes three parameters.
    307323\paragraph{Usage}
    308324cmemalign takes two parameters.
     325
    309326\begin{itemize}
    310327\item
     
    315332It returns a dynamic object that has the capacity to contain dim number of objects, each of the size of type T. The returned object is aligned to the given parameter align and is zero filled. On failure, it return NULL pointer.
    316333
    317 \subsubsection T * aligned_alloc( size_t align )
    318 This aligned_alloc is a simplified polymorphic form of defualt aligned_alloc (FIX ME: cite aligned_alloc). It takes one parameter as compared to the default aligned_alloc that takes two parameters.
    319 \paragraph{Usage}
    320 This aligned_alloc takes one parameter.
     334\subsubsection T * aligned\_alloc( size\_t align )
     335This aligned\_alloc is a simplified polymorphic form of defualt aligned\_alloc (FIX ME: cite aligned\_alloc). It takes one parameter as compared to the default aligned\_alloc that takes two parameters.
     336\paragraph{Usage}
     337This aligned\_alloc takes one parameter.
     338
    321339\begin{itemize}
    322340\item
     
    325343It returns a dynamic object of the size of type T that is aligned to the given parameter. On failure, it return NULL pointer.
    326344
    327 \subsubsection int posix_memalign( T ** ptr, size_t align )
    328 This posix_memalign is a simplified polymorphic form of defualt posix_memalign (FIX ME: cite posix_memalign). It takes two parameters as compared to the default posix_memalign that takes three parameters.
    329 \paragraph{Usage}
    330 This posix_memalign takes two parameter.
     345\subsubsection int posix\_memalign( T ** ptr, size\_t align )
     346This posix\_memalign is a simplified polymorphic form of defualt posix\_memalign (FIX ME: cite posix\_memalign). It takes two parameters as compared to the default posix\_memalign that takes three parameters.
     347\paragraph{Usage}
     348This posix\_memalign takes two parameter.
     349
    331350\begin{itemize}
    332351\item
     
    335354align: required alignment of the dynamic object.
    336355\end{itemize}
     356
    337357It stores address of the dynamic object of the size of type T in given parameter ptr. This object is aligned to the given parameter. On failure, it return NULL pointer.
    338358
     
    349369It returns a dynamic object of the size that is calcutaed by rouding the size of type T. The returned object is also aligned to the page size. On failure, it return NULL pointer.
    350370
    351 \subsection{Alloc Interface}
     371\subsection Alloc Interface
    352372In 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.
    353373This interface helps programmers in three major ways.
     374
    354375\begin{itemize}
    355376\item
     
    371392This 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.
    372393It represents the required number of members in the array allocation as in CFA's aalloc (FIX ME: cite aalloc).
    373 This parameter should be of type size_t.
     394This parameter should be of type size\_t.
    374395
    375396Example: int a = alloc( 5 )
     
    377398
    378399\paragraph{Align}
    379 This 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.
     400This 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.
    380401
    381402Example: int b = alloc( 5 , 64`align )
     
    385406This 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.
    386407Three types of parameters can be passed using `fill.
     408
    387409\begin{itemize}
    388410\item
Note: See TracChangeset for help on using the changeset viewer.