Fixed-width strings: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
(Changed from concept to description of implementation)
mNo edit summary
Line 162: Line 162:


A first implementation used a tree-based approach on top of in-place concatenation. Unfortunately, this resulted in large trees that held references to all right-hand-side strings, and the resulting flatten operation was highly recursive, which is not desirable for small devices. The current approach is a good compromise between low memory usage and a low number of string copy operations. Also, it reduces the number of objects that need to be marked during a GC operation.
A first implementation used a tree-based approach on top of in-place concatenation. Unfortunately, this resulted in large trees that held references to all right-hand-side strings, and the resulting flatten operation was highly recursive, which is not desirable for small devices. The current approach is a good compromise between low memory usage and a low number of string copy operations. Also, it reduces the number of objects that need to be marked during a GC operation.
=== Substrings ===
A substring is a dependent string, as above, that holds a reference to its master, the start and the length of the data. A substring of a substring does not reference a dependent string, but rather the master string itself.
Consider the above example:
<table border="1">
    <tr>
    <td colspan="4">len=2</td>
    <td colspan="4">left=0</td>
  </tr>
  <tr>
      <td>H</td>
      <td>i</td>
      <td>&nbsp;</td>
      <td>w</td>
      <td>o</td>
      <td>r</td>
      <td>l</td>
      <td>d</td>
  </tr>
</table>
substr (3, 5) would create this dependent string, pointing to "world":
<table border="1">
    <tr>
    <td colspan="8">pointer to master</td>
  </tr>
  <tr>
    <td colspan="4">start=3</td>
    <td colspan="4">len=5</td>
  </tr>
</table>
substr (3, 5).substr (0, 1) would then create this dependent string, where the master still is the original string:
<table border="1">
    <tr>
    <td colspan="8">pointer to master</td>
  </tr>
  <tr>
    <td colspan="4">start=3</td>
    <td colspan="4">len=1</td>
  </tr>
</table>


=== Static string data ===
=== Static string data ===
55

edits

Navigation menu