‹ BackHN Continuity

Thread

Modern Object Pascal Introduction for Programmers

204 points · 90 comments · birdculture

  1. mikewarot · · focus · HN ↗
    One of the greatest features of FreePascal is that strings are managed. You never allocate or deallocate them, you just declare the variable, and it manages them. They're counted, reference counted, copy on write, and can hold gigabytes.

    According to google:

    When you assign one dynamic string to another, Free Pascal does not duplicate the actual characters in memory. Instead, both variables point to the same character buffer in the heap, and the runtime increments an internal reference counter. A physical memory copy is only triggered when one of the string instances is modified (written to)

    Free Pascal strings are as close as you get to magic, compared to C/C++.

    1. Panzerschrek · · focus · HN ↗
      COW-strings aren't free. In a multithreaded environment they require atomic operations for use counter, which isn't cheap. Some time ago some implementations of C++ did use COW-strings too, but this approach was rejected due to such performance concerns.
      1. exceptione · · focus · HN ↗
        Many languages provide 2 primitives as we generally want 2 different concepts:

          String            -> immutable string
          StringBuilder     -> mutable string, optimized methods for string modification
    2. pjmlp · · focus · HN ↗
      Most of those ideas were present in PL/I, but we all know how it went.
    3. exceptione · · focus · HN ↗

        > Free Pascal strings are as close as you get to magic, compared to C/C++.
      
      Not your point of reference, but Java and C# treat strings as immutable objects too.
    4. sixthDot · · focus · HN ↗
      > strings are managed

      Actually all dynamic array are.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.