Why this code would require "memory allocation" (assuming this means allocating memory from a heap) is beyond me.
It's beyond me as well. It shouldn't be necessary. Freepascal does however output assembly to make a copy of the string parameter at the start of the function in case you want to modify it later (strings, unlike pchar's are not passed by reference).
I wouldn't do it this way. Freepascal compiler writers did. Yes you could change it and it would behave the same (and that's what I did in my kernel), however that does not mean the same assembly code is generated.
You two obviously don't understand the problem, which is that for the string version some undefined code will be output by the pascal compiler. Now if you ever want to change your compiler, you're screwed, because each compiler may treat the string type as it wishes, thus if you hack together some functions that behave like the string management routines used by freepascal you can't use them with any other pascal compiler. So you're stuck with a kernel tailored to a particular compiler. And also you can't use your strings before memory management is up and running (if you doubt me, take a look at the generated assembly code).
Imagine, why can I use BStrings properly (they are pointers to {length, allocated size, char data} structures) and you can't use pascal strings?.
Because, when you use BStrings you don't use any intrinsic compiler support, but rather your own functions to manipulate them. Obviously I can do the same with pascal strings: use a pointer to length, char data in pascal, because all pascal compilers treat pointers the same. However, once you declare your variable as a string, the compiler starts outputting function calls to rtl functions.
I don't understand what you don't understand. Surely you must be aware of the following?
- Declaring a variable as
string instantly breaks kernel compilation unless huge
compiler-specific remedies are made
- You can pass characters around using pchar (pointer to array of char). This is much faster than strings.
- If you need to concatenate pchars you need to write your own functions to do it, so strings are better. However, since the run-time-library doesn't work in your kernel unless you rewrote it, you'll have to write the functions either way.
- Array of char or Pchar is not in way, shape or form, related to string. PChar is a transparent datatype, string is an opaque datatype (that's where the problem comes from). C/C++ does not have opaque datatypes, which is probably why don't see the difference.