- Timestamp:
- Mar 6, 2020, 1:45:01 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- ca7949b
- Parents:
- 42a99b0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r42a99b0 r63aea5a 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Thu Mar 5 12:09:42 202014 %% Update Count : 3 88513 %% Last Modified On : Fri Mar 6 13:34:52 2020 14 %% Update Count : 3924 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 6621 6621 An array may be filled, resized, or aligned. 6622 6622 \end{description} 6623 \VRef[Table]{t:AllocationVersusCapabilities} shows allocation routines supporting different combinations of storage-management capabilities :6623 \VRef[Table]{t:AllocationVersusCapabilities} shows allocation routines supporting different combinations of storage-management capabilities. 6624 6624 \begin{table} 6625 6625 \centering 6626 \begin{minipage}{0.75\textwidth} 6626 6627 \begin{tabular}{@{}r|l|l|l|l|l@{}} 6627 6628 \multicolumn{1}{c}{}& & \multicolumn{1}{c|}{fill} & resize & alignment & array \\ … … 6631 6632 & ©realloc© & copy & yes & no & no \\ 6632 6633 & ©memalign© & no & no & yes & no \\ 6633 & ©aligned_alloc© & no & no & yes & no \\ 6634 & ©aligned_alloc©\footnote{Same as ©memalign© but size is an integral multiple of alignment, which is universally ignored.} 6635 & no & no & yes & no \\ 6634 6636 & ©posix_memalign© & no & no & yes & no \\ 6637 & ©valloc© & no & no & yes (page size)& no \\ 6638 & ©pvalloc©\footnote{Same as ©valloc© but rounds size to multiple of page size.} 6639 & no & no & yes (page size)& no \\ 6635 6640 \hline 6636 6641 \CFA & ©cmemalign© & yes (0 only) & no & yes & yes \\ 6637 6642 & ©realloc© & copy & yes & yes & no \\ 6638 & ©alloc© & no & no & no & no \\ 6639 & ©alloc© & copy & no/yes & no & yes \\ 6640 & ©alloc© & no/copy/yes & no/yes & no & yes \\ 6641 & ©alloc_set© & no/yes & no & yes & yes \\ 6642 & ©alloc_align© & no/yes & no & yes & yes \\ 6643 & ©alloc_align_set© & no/yes & no & yes & yes \\ 6643 & ©alloc© & no & yes & no & yes \\ 6644 & ©alloc_set© & yes & yes & no & yes \\ 6645 & ©alloc_align© & no & yes & yes & yes \\ 6646 & ©alloc_align_set© & yes & yes & yes & yes \\ 6644 6647 \end{tabular} 6648 \end{minipage} 6645 6649 \caption{Allocation Routines versus Storage-Management Capabilities} 6646 6650 \label{t:AllocationVersusCapabilities} 6647 6651 \end{table} 6652 6653 \CFA memory management extends the type safety of all allocations by using the type of the left-hand-side type to determine the allocation size and return a matching type for the new storage. 6654 Type-safe allocation is provided for all C allocation routines and new \CFA allocation routines, \eg in 6655 \begin{cfa} 6656 int * ip = (int *)malloc( sizeof(int) ); §\C{// C}§ 6657 int * ip = malloc(); §\C{// \CFA type-safe version of C malloc}§ 6658 int * ip = alloc(); §\C{// \CFA type-safe uniform alloc}§ 6659 \end{cfa} 6660 the latter two allocations determine the allocation size from the type of ©p© (©int©) and cast the pointer to the allocated storage to ©int *©. 6661 6662 \CFA memory management extends allocation safety by implicitly honouring all alignment requirements, \eg in 6663 \begin{cfa} 6664 struct S { int i; } __attribute__(( aligned( 128 ) )); // cache-line alignment 6665 S * sp = malloc(); §\C{// honour type alignment}§ 6666 \end{cfa} 6667 the storage allocation is implicitly aligned to 128 rather than the default 16. 6668 The alignment check is performed at compile time so there is no runtime cost. 6648 6669 6649 6670 \CFA memory management extends the resize capability with the notion of \newterm{sticky properties}. … … 6652 6673 Without sticky properties it is dangerous to use ©realloc©, resulting in an idiom of manually performing the reallocation to maintain correctness. 6653 6674 6675 \CFA memory management extends allocation to support constructors for initialization of allocated storage, \eg in 6676 \begin{cfa} 6677 struct S { int i; }; §\C{// cache-line aglinment}§ 6678 void ?{}( S & s, int i ) { s.i = i; } 6679 // assume ?|? operator for printing an S 6680 6681 S & sp = *®new®( 3 ); §\C{// call constructor after allocation}§ 6682 sout | sp.i; 6683 ®delete®( &sp ); 6684 6685 S * spa = ®anew®( 10, 5 ); §\C{// allocate array and initialize each array element}§ 6686 for ( i; 10 ) sout | spa[i] | nonl; 6687 sout | nl; 6688 ®adelete®( 10, spa ); 6689 \end{cfa} 6690 Allocation routines ©new©/©anew© allocate a variable/array and initialize storage using the allocated type's constructor. 6691 Note, the matching deallocation routines ©delete©/©adelete©. 6654 6692 6655 6693 \leavevmode
Note: See TracChangeset
for help on using the changeset viewer.