Ignore:
Timestamp:
Nov 11, 2024, 8:30:57 AM (5 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
2ae845e9, 7e943e1
Parents:
c01a2fd
Message:

more string changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/mike_brooks_MMath/string.tex

    rc01a2fd rb766c9b7  
    2525\end{tabular}
    2626\end{cquote}
    27 The key commonality is that operations work on groups of characters for assigning. copying, scanning, and updating,
     27The key commonality is that operations work on groups of characters for assigning. copying, scanning, and updating.
    2828Because a C string is null terminated and requires explicit storage management \see{\VRef{s:String}}, most of its group operations are error prone and expensive.
    2929Most high-level string libraries use a separate length field and specialized storage management to support group operations.
    30 \CC strings retains null termination to allow them to interface with C library functions requiring C strings.
     30\CC strings retain null termination to interface with library functions requiring C strings.
    3131\begin{cfa}
    3232int open( const char * pathname, int flags );
    33 string fname{ "abc" );
     33string fname{ "test.cc" );
    3434open( fname.@c_str()@ );
    3535\end{cfa}
    36 The function @c_str@ does not create a new null-terminated C string of the \CC string, as that requires passing ownership of the C string to the caller for eventual deletion.
     36The function @c_str@ does not create a new null-terminated C string from the \CC string, as that requires passing ownership of the C string to the caller for eventual deletion.\footnote{
     37C functions like \lstinline{strdup} do return allocated storage that must be freed by the caller.}
    3738Instead, each \CC string is null terminator just in case it might be needed for this purpose.
    38 Providing this backwards compatibility with C has a ubiquitous performance and storage cost even when this capability is not used.
     39Providing this backwards compatibility with C has a ubiquitous performance and storage cost.
    3940
    4041
     
    4243
    4344This section discusses issues related to storage management of strings.
    44 Specifically, it is common for strings to logically overlap completely or within a substring.
     45Specifically, it is common for strings to logically overlap completely or partially.
    4546\begin{cfa}
    4647string s1 = "abcdef";
    4748string s2 = s1; $\C{// complete overlap, s2 == "abcdef"}$
    48 string s3 = s1.substr( 0, 3 ); $\C{// substring overlap, s3 == "abc"}$
     49string s3 = s1.substr( 0, 3 ); $\C{// partial overlap, s3 == "abc"}$
    4950\end{cfa}
    5051This raises the question of how strings behave when an overlapping component is changed,
     
    5253s3[1] = 'w'; $\C{// what happens to s1 and s2?}$
    5354\end{cfa}
    54 \ie the notion of mutable and immutable strings.
    55 For example, Java has immutable strings so strings are copied when any overlapping string changes.
    56 Note, the notion of string mutability is not specified by @const@, \eg:
     55This question is the notion of mutable or immutable strings.
     56For example, Java has immutable strings that are copied when any overlapping string changes.
     57Note, the notion of underlying string mutability is not specified by @const@, \eg:
    5758\begin{cfa}
    5859const string s1 = "abc";
    5960\end{cfa}
    60 Here, @s1@ always points at @"abc"@, and @"abc"@ is an immutable constant, so all aspects of @s1@ are immutable.
    61 Because a string is an implicit pointer, there is no mechanism to write:
    62 \begin{cfa}
    63 const string @* const@ s1;
    64 \end{cfa}
    65 Hence, the underlying string is mutable.
     61Here, @const@ applies to the @s1@ pointer to @"abc"@, and @"abc"@ is an immutable constant that is \emph{copied} into the string's storage.
     62Hence, @s1@ is not pointing at an immutable constant, meaning its underlying string is always mutable, unless some other designation is specified, such as Java's global rule.
    6663
    6764
    6865\subsection{Logical overlap}
    6966
    70 Rather than have strings be either mutable or immutable, it is possible to mark them on assignment.
     67\CFA provides a dynamic mechanism to indicate mutable or immutable as an assignment attribute: @`shareEdits@.
    7168
    7269\input{sharing-demo.tex}
Note: See TracChangeset for help on using the changeset viewer.