Changeset d2260ad
- Timestamp:
- Jul 20, 2021, 9:31:45 PM (3 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mubeen_zulfiqar_MMath/allocator.tex
r8bf9448 rd2260ad 350 350 351 351 \subsection{Alloc Interface} 352 Why did we need it? 353 The added benefits. 352 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 This interface helps programmers in three major ways. 354 \begin{itemize} 355 \item 356 Routine Name: alloc interfce frees programmers from remmebring different routine names for different kind of dynamic allocations. 357 \item 358 Parametre Positions: alloc interface frees programmers from remembering parameter postions in call to routines. 359 \item 360 Object 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 363 Alloc 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( ... )} 366 Call to alloc wihout any parameter returns one object of size of type T allocated dynamically. 367 Only 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. 368 alocc 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} 371 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 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. 374 375 Example: int a = alloc( 5 ) 376 This call will return a dynamic array of five integers. 377 378 \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. 380 381 Example: int b = alloc( 5 , 64`align ) 382 This call will return a dynamic array of five integers. It will align the allocated object to 64. 383 384 \paragraph{Fill} 385 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 Three types of parameters can be passed using `fill. 387 \begin{itemize} 388 \item 389 char: 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 391 Object 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 393 Dynamic 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 396 Example: int b = alloc( 5 , 'a'`fill ) 397 This 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 399 Example: int b = alloc( 5 , 4`fill ) 400 This 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 402 Example: int b = alloc( 5 , a`fill ) where a is a pointer of int type 403 This 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} 406 This 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 409 resize to a new size. 410 \item 411 realign to a new alignment 412 \item 413 fill with something. 414 \end{itemize} 415 The 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 417 Example: int b = alloc( 5 , a`resize ) 418 This call will resize object a to a dynamic array that can contain 5 integers. 419 420 Example: int b = alloc( 5 , a`resize , 32`align ) 421 This call will resize object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32. 422 423 Example: int b = alloc( 5 , a`resize , 32`align , 2`fill) 424 This 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} 427 This 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 430 realloc to a new size. 431 \item 432 realign to a new alignment 433 \item 434 fill with something. 435 \end{itemize} 436 The 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 438 Example: int b = alloc( 5 , a`realloc ) 439 This call will realloc object a to a dynamic array that can contain 5 integers. 440 441 Example: int b = alloc( 5 , a`realloc , 32`align ) 442 This call will realloc object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32. 443 444 Example: int b = alloc( 5 , a`realloc , 32`align , 2`fill) 445 This 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.