Changeset 15885de9 for doc/theses/mubeen_zulfiqar_MMath/allocator.tex
- Timestamp:
- Oct 27, 2021, 10:05:59 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- a2e4b0c
- Parents:
- c600df1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mubeen_zulfiqar_MMath/allocator.tex
rc600df1 r15885de9 24 24 \end{itemize} 25 25 26 The new features added to uHeapLmmm (incl. @malloc _size@ routine)26 The new features added to uHeapLmmm (incl. @malloc\_size@ routine) 27 27 \CFA alloc interface with examples. 28 28 29 \begin{itemize} 29 30 \item … … 117 118 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 119 \subsubsection void * aalloc( size _t dim, size_t elemSize )120 \subsubsection void * aalloc( size\_t dim, size\_t elemSize ) 120 121 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 122 \paragraph{Usage} 122 123 aalloc takes two parameters. 124 123 125 \begin{itemize} 124 126 \item … … 129 131 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 132 131 \subsubsection void * resize( void * oaddr, size _t size )133 \subsubsection void * resize( void * oaddr, size\_t size ) 132 134 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 135 \paragraph{Usage} 134 136 resize takes two parameters. 137 135 138 \begin{itemize} 136 139 \item … … 141 144 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 145 143 \subsubsection void * resize( void * oaddr, size _t nalign, size_t size )146 \subsubsection void * resize( void * oaddr, size\_t nalign, size\_t size ) 144 147 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 148 \paragraph{Usage} 146 149 This resize takes three parameters. It takes an additional parameter of nalign as compared to the above resize (FIX ME: cite above resize). 150 147 151 \begin{itemize} 148 152 \item … … 155 159 It returns an object with the size and alignment given in the parameters. On failure, it returns a NULL pointer. 156 160 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 ) 158 162 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 163 \paragraph{Usage} 160 164 amemalign takes three parameters. 165 161 166 \begin{itemize} 162 167 \item … … 169 174 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 175 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 ) 172 177 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 178 \paragraph{Usage} 174 179 cmemalign takes three parameters. 180 175 181 \begin{itemize} 176 182 \item … … 183 189 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 190 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 ) 192 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. 193 \paragraph{Usage} 194 malloc\_alignment takes one parameters. 195 189 196 \begin{itemize} 190 197 \item 191 198 addr: the address of the currently allocated dynamic object. 192 199 \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. 200 malloc\_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 ) 203 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. 204 \paragraph{Usage} 205 malloc\_zero\_fill takes one parameters. 206 199 207 \begin{itemize} 200 208 \item 201 209 addr: the address of the currently allocated dynamic object. 202 210 \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. 211 malloc\_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 ) 214 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. 215 \paragraph{Usage} 216 malloc\_size takes one parameters. 217 209 218 \begin{itemize} 210 219 \item 211 220 addr: the address of the currently allocated dynamic object. 212 221 \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 )222 malloc\_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 ) 216 225 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 226 \paragraph{Usage} 218 227 This realloc takes three parameters. It takes an additional parameter of nalign as compared to the default realloc. 228 219 229 \begin{itemize} 220 230 \item … … 237 247 It returns a dynamic object of the size of type T. On failure, it return NULL pointer. 238 248 239 \subsubsection T * aalloc( size _t dim )249 \subsubsection T * aalloc( size\_t dim ) 240 250 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 251 \paragraph{Usage} 242 252 aalloc takes one parameters. 253 243 254 \begin{itemize} 244 255 \item … … 247 258 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 259 249 \subsubsection T * calloc( size _t dim )260 \subsubsection T * calloc( size\_t dim ) 250 261 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 262 \paragraph{Usage} 252 263 This calloc takes one parameter. 264 253 265 \begin{itemize} 254 266 \item … … 257 269 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 270 259 \subsubsection T * resize( T * ptr, size _t size )271 \subsubsection T * resize( T * ptr, size\_t size ) 260 272 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 273 \paragraph{Usage} 262 274 This resize takes two parameters. 275 263 276 \begin{itemize} 264 277 \item … … 269 282 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 283 271 \subsubsection T * realloc( T * ptr, size _t size )284 \subsubsection T * realloc( T * ptr, size\_t size ) 272 285 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 286 \paragraph{Usage} 274 287 This realloc takes two parameters. 288 275 289 \begin{itemize} 276 290 \item … … 281 295 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 296 283 \subsubsection T * memalign( size _t align )297 \subsubsection T * memalign( size\_t align ) 284 298 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 299 \paragraph{Usage} 286 300 memalign takes one parameters. 301 287 302 \begin{itemize} 288 303 \item … … 291 306 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 307 293 \subsubsection T * amemalign( size _t align, size_t dim )308 \subsubsection T * amemalign( size\_t align, size\_t dim ) 294 309 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 310 \paragraph{Usage} 296 311 amemalign takes two parameters. 312 297 313 \begin{itemize} 298 314 \item … … 303 319 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 320 305 \subsubsection T * cmemalign( size _t align, size_t dim )321 \subsubsection T * cmemalign( size\_t align, size\_t dim ) 306 322 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 323 \paragraph{Usage} 308 324 cmemalign takes two parameters. 325 309 326 \begin{itemize} 310 327 \item … … 315 332 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 333 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 ) 335 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. 336 \paragraph{Usage} 337 This aligned\_alloc takes one parameter. 338 321 339 \begin{itemize} 322 340 \item … … 325 343 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 344 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 ) 346 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. 347 \paragraph{Usage} 348 This posix\_memalign takes two parameter. 349 331 350 \begin{itemize} 332 351 \item … … 335 354 align: required alignment of the dynamic object. 336 355 \end{itemize} 356 337 357 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 358 … … 349 369 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. 350 370 351 \subsection {Alloc Interface}371 \subsection Alloc Interface 352 372 In 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. 353 373 This interface helps programmers in three major ways. 374 354 375 \begin{itemize} 355 376 \item … … 371 392 This 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. 372 393 It 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.394 This parameter should be of type size\_t. 374 395 375 396 Example: int a = alloc( 5 ) … … 377 398 378 399 \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.400 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. 380 401 381 402 Example: int b = alloc( 5 , 64`align ) … … 385 406 This 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. 386 407 Three types of parameters can be passed using `fill. 408 387 409 \begin{itemize} 388 410 \item
Note: See TracChangeset
for help on using the changeset viewer.