> The terminating zero doesn't prevent slicing (you can have a flag that
> indicates whether the terminator >exists) but slicing has inherent ownership
> problems that the more convoluted (string, startIndex) >solution has not.
> They are certainly not "always better".
Is that how the string is
Corresponding bug:
[https://github.com/nim-lang/Nim/issues/6541](https://github.com/nim-lang/Nim/issues/6541)
Yeah, we really need to fix that. :-)
The copy doesn’t worry me if the behavior is consistent. But, there is
something I don’t understand.
In this program
proc p() =
let x = "abc"
Run
there is a string copy (and an allocation) for "x".
But in this one
proc p() =
var a = "abc"
> eg: so the following will allocate 10 times (in D: 0 times):
Put it in a `main` proc. Allocates 0 times then. ;-)
> in my idea of an ideal string type, null termination would only occur for
> string literals (not on slices). I'll write more on this later, it requires a
> full design writeup t
> In Nim string literals do not allocate either, but assignments copy.
I wasn't sure whether "assignments" also meant "let a="abc" so I checked: after
further investigation by inserting logging inside copyString, looks like let
a="abc" does allocate (please correct if I'm wrong):
l
Ok, you're willing to pay the "penalty". I am not.
> Fully sliceable strings and arrays are always better.
The terminating zero doesn't preclude slicing (you can have a flag that
indicates whether the terminator exists) but slicing has inherent ownership
problems that the more convoluted `(stri
Doesn't Nim do the same mistake as C++ by adding the zero termination in the
string implementation?
The best solution in my opinion is to have an external "CString"
implementation. That will be a penalty for libraries that use zero terminated
strings. I'm willing to take that penalty for finall
1. In Nim string literals do not allocate either, but assignments copy.
2. They have a terminating zero for C interop.
3. The new string/seq implementation will eliminate more copies.
in D, string literals don't allocate. (in C as well but they decay to pointers
so let's leave these aside from this discussion)
D:
// D20180718T163602
import std.stdio;
extern(C) void fun(const(char)* str){
printf("std:{%s}\n", str);
}
void main(){
10 matches
Mail list logo