Changes in / [5bc81e9:4a3eb1c]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r5bc81e9 r4a3eb1c  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Tue Apr 23 14:13:10 2024
    14 %% Update Count     : 6623
     13%% Last Modified On : Thu Apr 18 21:53:45 2024
     14%% Update Count     : 6502
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    6969\lstset{language=CFA}                                                                   % CFA default lnaguage
    7070\lstnewenvironment{C++}[1][]                            % use C++ style
    71 {\lstset{language=C++,escapechar=§,moredelim=**[is][\protect\color{red}]{®}{®},#1}}
     71{\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®},#1}}
    7272{}
    7373
     
    29612961Since the strings overlap starting with the open bracket, ©[©, there is an ambiguous interpretation for the string.
    29622962
     2963{\color{red}
    29632964As well, \CFA-style declarations cannot be used to declare parameters for C-style routine-definitions because of the following ambiguity:
    29642965\begin{cfa}
     
    29662967int f( int (* foo) ); §\C{// foo is redefined as a parameter name}§
    29672968\end{cfa}
    2968 The string ``©int (* foo)©'' declares a C-style named-parameter of type pointer to an integer (the parenthesis are superfluous), while the same string declares a \CFA style unnamed parameter of type routine returning integer with unnamed parameter of type pointer to ©foo©.
     2969The string ``©int (* foo)©'' declares a C-style named-parameter of type pointer to an integer (the parenthesis are superfluous), while the same string declares a \CFA style unnamed parameter of type routine returning integer with unnamed parameter of type pointer to foo.
    29692970The redefinition of a type name in a parameter list is the only context in C where the character ©*© can appear to the left of a type name, and \CFA relies on all type qualifier characters appearing to the right of the type name.
    2970 The inability to use \CFA declarations in these two contexts is probably a blessing because it precludes programmers from arbitrarily switching between declarations forms within a declaration contexts.
     2971The inability to use \CFA declarations in these two contexts is probably a blessing because it precludes programmers from arbitrarily switching between declarations forms within a declaration contexts.}
    29712972
    29722973C-style declarations can be used to declare parameters for \CFA style routine definitions, \eg:
     
    30603061\subsection{Postfix Function}
    30613062\label{s:PostfixFunction}
    3062 \index{postfix function}
    30633063
    30643064\CFA provides an alternative call syntax where the argument appears before the function name.
     
    30813081'1'`m;
    30823082"123" "456"`m;
    3083 [1, 2, 3]`t;
     3083[1,2,3]`t;
    30843084\end{cfa}
    30853085&       
     
    31003100\end{tabular}
    31013101\end{cquote}
    3102 Note, to pass \emph{multiple} arguments to a postfix function requires a \Index{tuple}, \eg ©[1, 2, 3]`t©, which forms a single argument that is flattened into the multiple arguments \see{\VRef{s:Tuple}}.
    3103 Similarly, if the argument is an expression, it must be parenthesized, \eg ©(i + 3)`h©, or only the last operand of the expression is the argument, \eg ©i + (3`h)©.
    31043102
    31053103\VRef[Figure]{f:UnitsComparison} shows a common usage for postfix functions: converting basic literals into user literals.
     
    31263124        return l.stones + r.stones;
    31273125}
    3128 Weight ®?`st®( double w ) { return w; }
    3129 double ®?`st®( Weight w ) { return w.stones; }
    3130 Weight ®?`lb®( double w ) { return w / 14.0; }
    3131 double ®?`lb®( Weight w ) { return w.stones * 14.0; }
    3132 Weight ®?`kg®( double w ) { return w / 6.35; }
    3133 double ®?`kg®( Weight w ) { return w.stones * 6.35; }
     3126Weight ?`st( double w ) { return w; }
     3127double ?`st( Weight w ) { return w.stones; }
     3128Weight ?`lb( double w ) { return w / 14.0; }
     3129double ?`lb( Weight w ) { return w.stones * 14.0; }
     3130Weight ?`kg( double w ) { return w / 6.35; }
     3131double ?`kg( Weight w ) { return w.stones * 6.35; }
    31343132int main() {
    31353133        Weight w, heavy = { 20 }; // stones
    3136         w = 155®`lb®;
    3137         w = 0b_1111®`st®;
    3138         w = 0_233®`lb®;
    3139         w = 0x_9b®`kg®;
    3140         w = 5.5®`st® + 8®`kg® + 25.01®`lb® + heavy;
     3134        w = 155`lb;
     3135        w = 0b_1111`st;
     3136        w = 0_233`lb;
     3137        w = 0x_9b`kg;
     3138        w = 5.5`st + 8`kg + 25.01`lb + heavy;
    31413139}
    31423140\end{cfa}
     
    31513149        return l.stones + r.stones;
    31523150}
    3153 Weight operator®""_st®( long double w ) { return w; }
    3154 Weight operator®""_lb®( long double w ) { return w / 14.0; }
    3155 Weight operator®""_kg®( long double w ) { return w / 6.35; }
    3156 Weight operator®""_st®( unsigned long long int w ) { return w; }
    3157 Weight operator®""_lb®( unsigned long long int w ) { return w / 14.0; }
    3158 Weight operator®""_kg®( unsigned long long int w ) { return w / 6.35; }
     3151Weight operator""_st( long double w ) { return w; }
     3152Weight operator""_lb( long double w ) { return w / 14.0; }
     3153Weight operator""_kg( long double w ) { return w / 6.35; }
     3154Weight operator""_st( unsigned long long int w ) { return w; }
     3155Weight operator""_lb( unsigned long long int w ) { return w / 14.0; }
     3156Weight operator""_kg( unsigned long long int w ) { return w / 6.35; }
    31593157int main() {
    31603158        Weight w, heavy = { 20 }; // stones
    3161         w = 155®_lb®;
    3162         w = 0b1111®_st®;
    3163         w = 0'233®_lb®;         // quote separator
    3164         w = 0x9b®_kg®;
    3165         w = 5.5®_st® + 8®_kg® + 25.01®_lb® + heavy;
     3159        w = 155_lb;
     3160        w = 0b1111_st;
     3161        w = 0'233_lb;           // quote separator
     3162        w = 0x9b_kg;
     3163        w = 5.5_st + 8_kg + 25.01_lb + heavy;
    31663164}
    31673165\end{C++}
     
    35463544
    35473545\section{Tuple}
    3548 \label{s:Tuple}
    35493546
    35503547In C and \CFA, lists of elements appear in several contexts, such as the parameter list of a routine call.
     
    42054202[ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = §\emph{expr}§;
    42064203\end{cfa}
    4207 The left-hand side is a tuple of \LstBasicStyle{\emph{\Index{lvalue}}}s, which is a list of expressions each yielding an address, \ie any data object that can appear on the left-hand side of a conventional assignment statement.
     4204\index{lvalue}
     4205The left-hand side is a tuple of \LstBasicStyle{\emph{lvalues}}, which is a list of expressions each yielding an address, \ie any data object that can appear on the left-hand side of a conventional assignment statement.
    42084206\LstBasicStyle{\emph{expr}} is any standard arithmetic expression.
    42094207Clearly, the types of the entities being assigned must be type compatible with the value of the expression.
     
    42434241Multiple assignment has the following form:
    42444242\begin{cfa}
    4245 [ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = [ §\emph{expr}§, ... , §\emph{expr}§ ];§
    4246 \end{cfa}
    4247 The left-hand side is a tuple of \LstBasicStyle{\emph{\Index{lvalue}}}s, and the right-hand side is a tuple of \LstBasicStyle{\emph{expr}}s.
    4248 Each \LstBasicStyle{\emph{expr}} appearing on the right-hand side of a multiple assignment statement is assigned to the corresponding \LstBasicStyle{\emph{lvalues}} on the left-hand side of the statement using parallel semantics for each assignment.
     4243[ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = [ §\emph{expr}§, ... , §\emph{expr}§ ];
     4244\end{cfa}
     4245\index{lvalue}
     4246The left-hand side is a tuple of \emph{lvalues}, and the right-hand side is a tuple of \emph{expr}s.
     4247Each \emph{expr} appearing on the right-hand side of a multiple assignment statement is assigned to the corresponding \emph{lvalues} on the left-hand side of the statement using parallel semantics for each assignment.
    42494248An example of multiple assignment is:
    42504249\begin{cfa}
     
    81438142\section{Standard Library}
    81448143\label{s:StandardLibrary}
    8145 \index{standard library}
    81468144
    81478145The \CFA standard-library extends existing C library routines by adding new function, wrapping existing explicitly-polymorphic C routines into implicitly-polymorphic versions, and adding new \CFA extensions.
     
    81508148\subsection{Dynamic Storage-Management}
    81518149\label{s:DynamicStorageManagement}
    8152 \index{dynamic storage-management}\index{storage management}
    81538150
    81548151Dynamic storage-management in C is based on explicit allocation and deallocation (©malloc©/©free©).
     
    82138210\begin{enumerate}[leftmargin=\parindent]
    82148211\item
    8215 extends type safety of all allocation routines by using the left-hand assignment type to determine the allocation size and alignment, and return a matching type for the new storage, which removes many common allocation errors.
     8212Extend type safety of all allocation routines by using the left-hand assignment type to determine the allocation size and alignment, and return a matching type for the new storage, which removes many common allocation errors.
    82168213\begin{cfa}
    82178214int * ip = (int *)malloc( sizeof(int) ); §\C[2.3in]{// C}§
    82188215int * ip = malloc();                                    §\C{// \CFA type-safe call of C malloc}§
    8219 int * ip = calloc();                                    §\C{// \CFA type-safe call of C calloc}§
    8220 struct __attribute__(( aligned(128) )) spinlock { ... }; // cache alignment
     8216int * ip = alloc();                                             §\C{// \CFA type-safe call of \CFA alloc}§
     8217struct __attribute__(( aligned(128) )) spinlock { ... };
    82218218spinlock * slp = malloc();                              §\C{// correct size, alignment, and return type}\CRT§
    82228219\end{cfa}
     
    82248221
    82258222\item
    8226 introduces the notion of \newterm{sticky properties} used in resizing.
     8223Introduce the notion of \newterm{sticky properties} used in resizing.
    82278224All initial allocation properties are remembered and maintained for use should resize require new storage.
    82288225For example, the initial alignment and fill properties in the initial allocation
     
    82368233
    82378234\item
    8238 provides resizing without data copying, which is useful to repurpose an existing block of storage, rather than freeing the old storage and performing a new allocation.
    8239 A resize can take advantage of unused storage after the data to preventing a free/reallocation step altogether.
    8240 
    8241 \item
    8242 provides ©free©/©delete© functions that delete a variable number of allocations.
     8235Provide resizing without data copying, which is useful to repurpose an existing block of storage for another purpose, rather than freeing the old storage and performing a new allocation.
     8236The resize might be able to take advantage of unused storage after the data to preventing the free/reallocation step altogether.
     8237
     8238\item
     8239Provide ©free©/©delete© functions that delete a variable number of pointers.
    82438240\begin{cfa}
    82448241int * ip = malloc(), * jp = malloc(), * kp = malloc();
    82458242double * xp = malloc(), * yp = malloc(), * zp = malloc();
    8246 free( ®ip, jp, kp, xp, yp, zp® );               §\C{// multiple deallocations}§
    8247 \end{cfa}
    8248 
    8249 \item
    8250 supports constructors for initialization of allocated storage and destructors for deallocation (like \CC).
     8243free( ®ip, jp, kp, xp, yp, zp® );
     8244\end{cfa}
     8245
     8246\item
     8247Support constructors for initialization of allocated storage (like \CC) and destructors for deallocation.
    82518248\begin{cfa}
    82528249struct S { int v; };                                    §\C{// default constructors}§
     
    82648261Allocation routines ©new©/©anew© allocate a variable/array and initialize storage using the allocated type's constructor.
    82658262Note, the matching deallocation routines ©delete©/©adelete©.
    8266 \CC only supports the default constructor for intializing array elements.
    8267 \begin{C++}
    8268 S * sp = new S[10]®{5}®;                                §\C{// disallowed}§
    8269 \end{C++}
    82708263\end{enumerate}
    82718264
     
    82818274\end{enumerate}
    82828275
    8283 The polymorphic functions
    8284 \begin{cfa}
    8285 T * alloc( ... );
    8286 T * alloc( size_t dim, ... );
    8287 \end{cfa}
    8288 are overloaded with a variable number of allocation properties.
    8289 These allocation properties can be passed as named arguments when calling the \Indexc{alloc} routine.
    8290 A call without parameters returns an uninitialized dynamically allocated object of type ©T© (\Indexc{malloc}).
    8291 A call with only the dimension (dim) parameter returns an uninitialized dynamically allocated array of objects with type ©T© (\Indexc{aalloc}).
    8292 The variable number of arguments consist of allocation properties to specialize the allocation.
    8293 The properties ©resize© and ©realloc© are associated with an existing allocation variable indicating how its storage is modified.
     8276The polymorphic functions ©T * alloc( ... )© and ©T * alloc( size_t dim, ... )© are overloaded with a variable number of specific allocation properties, or an integer dimension parameter followed by a variable number of specific allocation properties.
     8277These allocation properties can be passed as named arguments when calling the \lstinline{alloc} routine.
     8278A call without parameters returns an uninitialized dynamically allocated object of type ©T© (©malloc©).
     8279A call with only the dimension (dim) parameter returns an uninitialized dynamically allocated array of objects with type ©T© (©aalloc©).
     8280The variable number of arguments consist of allocation properties, which can be combined to produce different kinds of allocations.
     8281The properties ©resize© and ©realloc© are associated with the allocation variable indicating how the existing allocation is modified, without or with data copying.
     8282Function ©alloc© is used extensively in the \CFA runtime.
    82948283
    82958284The following allocation property functions may be combined and appear in any order as arguments to ©alloc©,
     
    82978286\item
    82988287©T_align ?`align( size_t alignment )© to align an allocation.
    8299 The alignment parameter must be $\ge$ the default alignment (©libAlign()© in \CFA) and a power of two, \eg the following return a dynamic object and object array aligned on a 256 and 4096-byte boundary.
    8300 \begin{cfa}
    8301 int * i0 = alloc( ®256`align® );  sout | i0 | nl;
    8302 int * i1 = alloc( 3, ®4096`align® );  for (i; 3 ) sout | &i1[i] | nonl; sout | nl;
    8303 free( i0, i1 );
    8304 
    8305 0x5555565699®00®  // 256 alignment
    8306 0x55555656c®000® 0x5656c004 0x5656c008  // 4K array alignment
    8307 \end{cfa}
    8308 
    8309 \item
    8310 ©T_fill(T) ?`fill( /* various types */ )© to initialize storage.
     8288The alignment parameter must be $\ge$ the default alignment (©libAlign()© in \CFA) and a power of two, \eg:
     8289\begin{cfa}
     8290int * i0 = alloc( ®4096`align® );  sout | i0 | nl;
     8291int * i1 = alloc( 3, ®4096`align® );  sout | i1; for (i; 3 ) sout | &i1[i] | nonl; sout | nl;
     8292
     82930x555555572000
     82940x555555574000 0x555555574000 0x555555574004 0x555555574008
     8295\end{cfa}
     8296returns a dynamic object and object array aligned on a 4096-byte boundary.
     8297
     8298\item
     8299©S_fill(T) ?`fill ( /* various types */ )© to initialize storage.
    83118300There are three ways to fill storage:
    83128301\begin{enumerate}
     
    83208309For example:
    83218310\begin{cfa}[numbers=left]
    8322 int * i0 = alloc( ®0n`fill® );  sout | *i0 | nl;  // 0n disambiguates 0p
     8311int * i0 = alloc( ®0n`fill® );  sout | *i0 | nl;  // 0n disambiguates 0
    83238312int * i1 = alloc( ®5`fill® );  sout | *i1 | nl;
    83248313int * i2 = alloc( ®'\xfe'`fill® ); sout | hex( *i2 ) | nl;
     
    83278316int * i5 = alloc( 5, ®i3`fill® );  for ( i; 5 ) sout | i5[i] | nonl; sout | nl; // completely fill from i3
    83288317int * i6 = alloc( 5, ®[i3, 3]`fill® );  for ( i; 5 ) sout | i6[i] | nonl; sout | nl; // partial fill from i3
    8329 free( i0, i1, i2, i3, i4, i5, i6 );
    83308318\end{cfa}
    83318319\begin{lstlisting}[numbers=left]
     
    83468334For example:
    83478335\begin{cfa}[numbers=left]
    8348 int * ip = alloc( ®5`fill® );  sout | ip | *ip;
    8349 ip = alloc( ®ip`resize®, ®256`align®, ®7`fill® );  sout | ip | *ip;
    8350 double * dp = alloc( ®ip`resize®, ®4096`align®, ®13.5`fill® );  sout | dp | *dp;
    8351 free( dp );  // DO NOT FREE ip AS ITS STORAGE IS MOVED TO dp
     8336int * i = alloc( ®5`fill® );  sout | i | *i;
     8337i = alloc( ®i`resize®, ®256`align®, ®7`fill® );  sout | i | *i;
     8338double * d = alloc( ®i`resize®, ®4096`align®, ®13.5`fill® );  sout | d | *d;
    83528339\end{cfa}
    83538340\begin{lstlisting}[numbers=left]
    8354 0x555555580a80 5
    8355 0x555555581100 7
    8356 0x555555587000 13.5
     83410x55555556d5c0 5
     83420x555555570000 7
     83430x555555571000 13.5
    83578344\end{lstlisting}
    83588345Examples 2 to 3 change the alignment, fill, and size for the initial storage of ©i©.
    83598346
    83608347\begin{cfa}[numbers=left]
    8361 int * ia = alloc( 5, ®5`fill® );  sout | ia | nonl;  for ( i; 5 ) sout | ia[i] | nonl; sout | nl;
    8362 ia = alloc( 10, ®ia`resize®, ®7`fill® );  sout | ia | nonl;  for ( i; 10 ) sout | ia[i] | nonl; sout | nl;
    8363 ia = alloc( 5, ®ia`resize®, ®512`align®, ®13`fill® ); sout | ia | nonl; for ( i; 5 ) sout | ia[i] | nonl; sout | nl;;
    8364 ia = alloc( 3, ®ia`resize®, ®4096`align®, ®2`fill® );  for ( i; 3 ) sout | &ia[i] | ia[i] | nonl; sout | nl;
    8365 free( ia );
     8348int * ia = alloc( 5, ®5`fill® );  for ( i; 5 ) sout | ia[i] | nonl; sout | nl;
     8349ia = alloc( 10, ®ia`resize®, ®7`fill® ); for ( i; 10 ) sout | ia[i] | nonl; sout | nl;
     8350sout | ia; ia = alloc( 5, ®ia`resize®, ®512`align®, ®13`fill® ); sout | ia; for ( i; 5 ) sout | ia[i] | nonl; sout | nl;;
     8351ia = alloc( 3, ®ia`resize®, ®4096`align®, ®2`fill® );  sout | ia; for ( i; 3 ) sout | &ia[i] | ia[i] | nonl; sout | nl;
    83668352\end{cfa}
    83678353\begin{lstlisting}[numbers=left]
    8368 0x55555656d540 5 5 5 5 5
    8369 0x55555656d480 7 7 7 7 7 7 7 7 7 7
    8370 0x55555656fe00 13 13 13 13 13
    8371 0x555556570000 2 0x555556570004 2 0x555556570008 2
     83545 5 5 5 5
     83557 7 7 7 7 7 7 7 7 7
     83560x55555556d560 0x555555571a00 13 13 13 13 13
     83570x555555572000 0x555555572000 2 0x555555572004 2 0x555555572008 2
    83728358\end{lstlisting}
    8373 Examples 2 to 4 change the array size, alignment, and fill initializes all storage because no data is copied.
     8359Examples 2 to 4 change the array size, alignment and fill for the initial storage of ©ia©.
    83748360
    83758361\item
     
    83808366For example:
    83818367\begin{cfa}[numbers=left]
    8382 int * ip = alloc( ®5`fill® );  sout | ip | *ip;
    8383 ip = alloc( ®ip`realloc®, ®256`align® );  sout | ip | *ip;
    8384 ip = alloc( ®ip`realloc®, ®4096`align®, ®13`fill® );  sout | ip | *ip;
    8385 free( ip );
     8368int * i = alloc( ®5`fill® );  sout | i | *i;
     8369i = alloc( ®i`realloc®, ®256`align® );  sout | i | *i;
     8370i = alloc( ®i`realloc®, ®4096`align®, ®13`fill® );  sout | i | *i;
    83868371\end{cfa}
    83878372\begin{lstlisting}[numbers=left]
     
    83918376\end{lstlisting}
    83928377Examples 2 to 3 change the alignment for the initial storage of ©i©.
    8393 The ©13`fill© in example 3 does nothing because no new storage is added.
     8378The ©13`fill© in example 3 does nothing because no extra space is added.
    83948379
    83958380\begin{cfa}[numbers=left]
    8396 int * ia = alloc( 5, ®5`fill® );  sout | ia | nonl;  for ( i; 5 ) sout | ia[i] | nonl; sout | nl;
    8397 ia = alloc( 10, ®ia`realloc®, ®7`fill® );  sout | ia | nonl;  for ( i; 10 ) sout | ia[i] | nonl; sout | nl;
    8398 ia = alloc( 5, ®ia`realloc®, ®512`align®, ®13`fill® );  sout | ia | nonl; for ( i; 5 ) sout | ia[i] | nonl; sout | nl;;
    8399 ia = alloc( 3, ®ia`realloc®, ®4096`align®, ®2`fill® );  for ( i; 3 ) sout | &ia[i] | ia[i] | nonl; sout | nl;
    8400 free( ia );
     8381int * ia = alloc( 5, ®5`fill® );  for ( i; 5 ) sout | ia[i]; sout | nl;
     8382ia = alloc( 10, ®ia`realloc®, ®7`fill® ); for ( i; 10 ) sout | ia[i]; sout | nl;
     8383sout | ia; ia = alloc( 1, ®ia`realloc®, ®512`align®, ®13`fill® ); sout | ia; for ( i; 1 ) sout | ia[i]; sout | nl;;
     8384ia = alloc( 3, ®ia`realloc®, ®4096`align®, ®2`fill® );  sout | ia; for ( i; 3 ) sout | &ia[i] | ia[i]; sout | nl;
    84018385\end{cfa}
    84028386\begin{lstlisting}[numbers=left]
    8403 0x55555656d540 5 5 5 5 5
    8404 0x55555656d480 7 7 7 7 7 7 7 7 7 7
    8405 0x555556570e00 5 5 5 5 5
    8406 0x5555556571000 5 0x555556571004 5 0x555556571008 5
     83875 5 5 5 5
     83885 5 5 5 5 7 7 7 7 7
     83890x55555556c560 0x555555570a00 5
     83900x555555571000 0x555555571000 5 0x555555571004 2 0x555555571008 2
    84078391\end{lstlisting}
    8408 Examples 2 to 4 change the array size, alignment, and fill does no initialization after the copied data, as no new storage is added.
     8392Examples 2 to 4 change the array size, alignment and fill for the initial storage of ©ia©.
     8393The ©13`fill© in example 3 does nothing because no extra space is added.
    84098394\end{itemize}
    84108395
     
    84128397\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    84138398extern "C" {
    8414         // New C allocation operations.
     8399        // New allocation operations.
    84158400        void * aalloc( size_t dim, size_t elemSize );§\indexc{aalloc}§
    84168401        void * resize( void * oaddr, size_t size );§\indexc{resize}§
     
    84218406        size_t malloc_size( void * addr );§\indexc{malloc_size}§
    84228407        int malloc_stats_fd( int fd );§\indexc{malloc_stats_fd}§
    8423         size_t malloc_expansion();§\indexc{malloc_expansion}§ §\C{// heap expansion size (bytes)}§
    8424         size_t malloc_mmap_start();§\indexc{malloc_mmap_start}§ §\C{// crossover allocation size from sbrk to mmap}§
    8425         size_t malloc_unfreed();§\indexc{malloc_unfreed()}§     §\C{// heap unfreed size (bytes)}§
    8426         void malloc_stats_clear();§\indexc{malloc_stats_clear}§ §\C{// clear heap statistics}§
     8408        size_t malloc_expansion();§\indexc{malloc_expansion}§ $\C{// heap expansion size (bytes)}$
     8409        size_t malloc_mmap_start();§\indexc{malloc_mmap_start}§ $\C{// crossover allocation size from sbrk to mmap}$
     8410        size_t malloc_unfreed();§\indexc{malloc_unfreed()}§     $\C{// heap unfreed size (bytes)}$
     8411        void malloc_stats_clear();§\indexc{malloc_stats_clear}§ $\C{// clear heap statistics}$
    84278412}
    84288413
     
    84388423        T * calloc( size_t dim );§\indexc{calloc}§
    84398424        T * resize( T * ptr, size_t size );§\indexc{resize}§
    8440         T * resize( T * ptr, size_t alignment, size_t size );
    84418425        T * realloc( T * ptr, size_t size );§\indexc{realloc}§
    8442         T * realloc( T * ptr, size_t alignment, size_t size );
    84438426        T * reallocarray( T * ptr, size_t dim );§\indexc{reallocarray}§
    8444         T * reallocarray( T * ptr, size_t alignment, size_t dim );
    84458427        T * memalign( size_t align );§\indexc{memalign}§
    84468428        T * amemalign( size_t align, size_t dim );§\indexc{amemalign}§
     
    84558437        T * alloc( size_t dim, ... );
    84568438        T_align ?`align( size_t alignment );§\indexc{align}§
    8457         T_fill(T) ?`fill( /* various types */ );§\indexc{fill}§
    8458         T_resize ?`resize( void * oaddr );§\indexc{resize}§
    8459         T_realloc ?`realloc( void * oaddr ));§\indexc{realloc}§
    8460 }
    8461 
    8462 forall( T &, List ... ) void free( T * ptr, ... ) // deallocation list
     8439        S_fill(T) ?`fill( /* various types */ );§\indexc{fill}§
     8440        S_resize(T) ?`resize( void * oaddr );§\indexc{resize}§
     8441        S_realloc(T) ?`realloc( T * a ));§\indexc{realloc}§
     8442
     8443        // §\CFA§ safe initialization/copy, i.e., implicit size specification
     8444        T * memset( T * dest, char fill );§\indexc{memset}§
     8445        T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
     8446
     8447        // §\CFA§ safe initialization/copy, i.e., implicit size specification, array types
     8448        T * amemset( T dest[], char fill, size_t dim );
     8449        T * amemcpy( T dest[], const T src[], size_t dim );
     8450}
    84638451
    84648452// §\CFA§ allocation/deallocation and constructor/destructor, non-array types
    8465 forall( T &, Parms ... | { void ?{}( T &, Parms ); } ) T * new( Parms ... );§\indexc{new}§
    8466 forall( T &, List ... | { void ^?{}( T & ); void delete( List ... ); } );§\indexc{delete}§
     8453forall( T &, TT ... ) void free( T * ptr, ... );
     8454
     8455forall( T & | sized(T), Params ... | { void ?{}( T &, Params ); } )
     8456T * new( Params p );§\indexc{new}§
     8457forall( T & | { void ^?{}( T & ); } )
     8458void delete( T * ptr );§\indexc{delete}§
     8459forall( T &, Params ... | { void ^?{}( T & ); void delete( Params ); } )
     8460void delete( T * ptr, Params rest );
     8461
    84678462// §\CFA§ allocation/deallocation and constructor/destructor, array types
    8468 forall( T & | sized(T), Parms ... | { void ?{}( T &, Parms ); } ) T * anew( size_t dim, Parms ... );§\indexc{anew}§
    8469 forall( T & | sized(T) | { void ^?{}( T & ); }, List ... } ) void adelete( T arr[], List ... );§\indexc{adelete}§
    8470 \end{cfa}
    8471 
    8472 
    8473 \subsection{Memory Set and Copy}
    8474 
    8475 Like safe memory allocation, \CFA provides safe block initialization and copy.
    8476 While objects should be initialized/copied with constructors/assignment, block operations can be very performant.
    8477 In certain cases the compiler generates block copy operations, such as assigning structures ©s = t©, however C arrays cannot be assigned.
    8478 \begin{cquote}
    8479 \begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8480 struct S { int i, j, k; };
    8481 S s, t, *sp = &s, * tp = &t, sa[10], ta[10];
    8482 \end{cfa}
    8483 \noindent
    8484 \begin{tabular}{@{}l|l@{}}
    8485 \multicolumn{1}{@{}c|}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\
    8486 \begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8487 memset( s, '\0' );
    8488 memset( sp, '\0' );
    8489 
    8490 memcpy( s, t );
    8491 memcpy( sp, tp );
    8492 
    8493 amemset( sa, '\0', 10 );
    8494 amemcpy( sa, ta, 10 );
    8495 \end{cfa}
    8496 &
    8497 \begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8498 memset( &s, '\0', sizeof(s) );
    8499 memset( sp, '\0', sizeof(s) );
    8500 
    8501 memcpy( &s, &t, sizeof(s) );
    8502 memcpy( sp, tp, sizeof(s) );
    8503 
    8504 memset( sa, '\0', sizeof(sa) );
    8505 memcpy( sa, ta, sizeof(sa) );
    8506 \end{cfa}
    8507 \end{tabular}
    8508 \end{cquote}
    8509 These operations provide uniformity between reference and pointer, so object dereferencing, '©&©', is unnecessary.
    8510 
    8511 \begin{cfa}
    8512 static inline forall( T & | sized(T) ) {
    8513         // CFA safe initialization/copy, i.e., implicit size specification, non-array types
    8514         T * memset( T * dest, char fill );§\indexc{memset}§     §\C{// all combinations of pointer/reference}§
    8515         T * memset( T & dest, char fill );
    8516 
    8517         T * memcpy( T * dest, const T * src );§\indexc{memcpy}§ §\C{// all combinations of pointer/reference}§
    8518         T * memcpy( T & dest, const T & src );
    8519         T * memcpy( T * dest, const T & src );
    8520         T * memcpy( T & dest, const T * src );
    8521 
    8522         // CFA safe initialization/copy, i.e., implicit size specification, array types
    8523         T * amemset( T dest[], char fill, size_t dim );§\indexc{memcpy}§
    8524         T * amemcpy( T dest[], const T src[], size_t dim );
    8525 }
     8463forall( T & | sized(T), Params ... | { void ?{}( T &, Params ); } )
     8464T * anew( size_t dim, Params p );§\indexc{anew}§
     8465forall( T & | sized(T) | { void ^?{}( T & ); } )
     8466void adelete( T arr[] );§\indexc{adelete}§
     8467forall( T & | sized(T) | { void ^?{}( T & ); }, Params ... | { void adelete( Params ); } )
     8468void adelete( T arr[], Params rest );
    85268469\end{cfa}
    85278470
Note: See TracChangeset for help on using the changeset viewer.