Changeset 1f8dbfe for doc/theses/mubeen_zulfiqar_MMath/allocator.tex
- Timestamp:
- Jul 20, 2021, 12:57:58 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 815c6ae
- Parents:
- f9b68d6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mubeen_zulfiqar_MMath/allocator.tex
rf9b68d6 r1f8dbfe 111 111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 112 112 113 \section{Added Features} 114 115 116 \subsection{Methods} 117 Why did we need it? 118 The added benefits. 119 113 \section{Added Features and Methods} 114 To improve the UHeapLmmm allocator (FIX ME: cite uHeapLmmm) interface and make it more user friendly, we added a few more routines to the C allocator. Also, we built a CFA (FIX ME: cite cforall) interface on top of C interface to increase the usability of the allocator. 115 116 \subsection{C Interface} 117 We 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. 118 119 \subsubsection void * aalloc( size_t dim, size_t elemSize ) 120 aalloc 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. 121 \paragraph{Usage} 122 aalloc takes two parameters. 123 \begin{itemize} 124 \item 125 dim: number of objects in the array 126 \item 127 elemSize: size of the object in the array. 128 \end{itemize} 129 It 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. 130 131 \subsubsection void * resize( void * oaddr, size_t size ) 132 resize 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. 133 \paragraph{Usage} 134 resize takes two parameters. 135 \begin{itemize} 136 \item 137 oaddr: the address of the old object that needs to be resized. 138 \item 139 size: the new size requirement of the to which the old object needs to be resized. 140 \end{itemize} 141 It 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. 142 143 \subsubsection void * resize( void * oaddr, size_t nalign, size_t size ) 144 This 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. 145 \paragraph{Usage} 146 This resize takes three parameters. It takes an additional parameter of nalign as compared to the above resize (FIX ME: cite above resize). 147 \begin{itemize} 148 \item 149 oaddr: the address of the old object that needs to be resized. 150 \item 151 nalign: the new alignment to which the old object needs to be realigned. 152 \item 153 size: the new size requirement of the to which the old object needs to be resized. 154 \end{itemize} 155 It returns an object with the size and alignment given in the parameters. On failure, it returns a NULL pointer. 156 157 \subsubsection void * amemalign( size_t alignment, size_t dim, size_t elemSize ) 158 amemalign 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. 159 \paragraph{Usage} 160 amemalign takes three parameters. 161 \begin{itemize} 162 \item 163 alignment: the alignment to which the dynamic array needs to be aligned. 164 \item 165 dim: number of objects in the array 166 \item 167 elemSize: size of the object in the array. 168 \end{itemize} 169 It 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. 170 171 \subsubsection void * cmemalign( size_t alignment, size_t dim, size_t elemSize ) 172 cmemalign 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. 173 \paragraph{Usage} 174 cmemalign takes three parameters. 175 \begin{itemize} 176 \item 177 alignment: the alignment to which the dynamic array needs to be aligned. 178 \item 179 dim: number of objects in the array 180 \item 181 elemSize: size of the object in the array. 182 \end{itemize} 183 It 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. 184 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. 189 \begin{itemize} 190 \item 191 addr: the address of the currently allocated dynamic object. 192 \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. 199 \begin{itemize} 200 \item 201 addr: the address of the currently allocated dynamic object. 202 \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. 209 \begin{itemize} 210 \item 211 addr: the address of the currently allocated dynamic object. 212 \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 ) 216 This 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. 217 \paragraph{Usage} 218 This realloc takes three parameters. It takes an additional parameter of nalign as compared to the default realloc. 219 \begin{itemize} 220 \item 221 oaddr: the address of the old object that needs to be reallocated. 222 \item 223 nalign: the new alignment to which the old object needs to be realigned. 224 \item 225 size: the new size requirement of the to which the old object needs to be resized. 226 \end{itemize} 227 It returns an object with the size and alignment given in the parameters that preserves the data in the old object. On failure, it returns a NULL pointer. 228 229 \subsection{CFA Malloc Interface} 230 We added some routines to the malloc interface of CFA. These routines can only be used in CFA and not in our standalone uHeapLmmm allocator as these routines use some features that are only provided by CFA and not by C. It makes the allocator even more usable to the programmers. 231 CFA provides the liberty to know the returned type of a call to the allocator. So, mainly in these added routines, we removed the object size parameter from the routine as allocator can calculate the size of the object from the returned type. 232 233 \subsubsection T * malloc( void ) 234 This malloc is a simplified polymorphic form of defualt malloc (FIX ME: cite malloc). It does not take any parameter as compared to default malloc that takes one parameter. 235 \paragraph{Usage} 236 This malloc takes no parameters. 237 It returns a dynamic object of the size of type T. On failure, it return NULL pointer. 238 239 \subsubsection T * aalloc( size_t dim ) 240 This 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. 241 \paragraph{Usage} 242 aalloc takes one parameters. 243 \begin{itemize} 244 \item 245 dim: required number of objects in the array. 246 \end{itemize} 247 It 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. 248 249 \subsubsection T * calloc( size_t dim ) 250 This 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. 251 \paragraph{Usage} 252 This calloc takes one parameter. 253 \begin{itemize} 254 \item 255 dim: required number of objects in the array. 256 \end{itemize} 257 It 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. 258 259 \subsubsection T * resize( T * ptr, size_t size ) 260 This 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. 261 \paragraph{Usage} 262 This resize takes two parameters. 263 \begin{itemize} 264 \item 265 ptr: address of the old object. 266 \item 267 size: the required size of the new object. 268 \end{itemize} 269 It 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. 270 271 \subsubsection T * realloc( T * ptr, size_t size ) 272 This 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. 273 \paragraph{Usage} 274 This realloc takes two parameters. 275 \begin{itemize} 276 \item 277 ptr: address of the old object. 278 \item 279 size: the required size of the new object. 280 \end{itemize} 281 It 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. 282 283 \subsubsection T * memalign( size_t align ) 284 This 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. 285 \paragraph{Usage} 286 memalign takes one parameters. 287 \begin{itemize} 288 \item 289 align: the required alignment of the dynamic object. 290 \end{itemize} 291 It returns a dynamic object of the size of type T that is aligned to given parameter align. On failure, it return NULL pointer. 292 293 \subsubsection T * amemalign( size_t align, size_t dim ) 294 This 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. 295 \paragraph{Usage} 296 amemalign takes two parameters. 297 \begin{itemize} 298 \item 299 align: required alignment of the dynamic array. 300 \item 301 dim: required number of objects in the array. 302 \end{itemize} 303 It 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. 304 305 \subsubsection T * cmemalign( size_t align, size_t dim ) 306 This 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. 307 \paragraph{Usage} 308 cmemalign takes two parameters. 309 \begin{itemize} 310 \item 311 align: required alignment of the dynamic array. 312 \item 313 dim: required number of objects in the array. 314 \end{itemize} 315 It 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. 316 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. 321 \begin{itemize} 322 \item 323 align: required alignment of the dynamic object. 324 \end{itemize} 325 It returns a dynamic object of the size of type T that is aligned to the given parameter. On failure, it return NULL pointer. 326 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. 331 \begin{itemize} 332 \item 333 ptr: variable address to store the address of the allocated object. 334 \item 335 align: required alignment of the dynamic object. 336 \end{itemize} 337 It 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. 338 339 \subsubsection T * valloc( void ) 340 This valloc is a simplified polymorphic form of defualt valloc (FIX ME: cite valloc). It takes no parameters as compared to the default valloc that takes one parameter. 341 \paragraph{Usage} 342 valloc takes no parameters. 343 It returns a dynamic object of the size of type T that is aligned to the page size. On failure, it return NULL pointer. 344 345 \subsubsection T * pvalloc( void ) 346 This pcvalloc is a simplified polymorphic form of defualt pcvalloc (FIX ME: cite pcvalloc). It takes no parameters as compared to the default pcvalloc that takes one parameter. 347 \paragraph{Usage} 348 pvalloc takes no parameters. 349 It 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. 120 350 121 351 \subsection{Alloc Interface}
Note: See TracChangeset
for help on using the changeset viewer.