Re: string literals should not allocate; should allocate in ROM an extra `\0`

2018-07-22 Thread RodSteward
> 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

Re: string literals should not allocate; should allocate in ROM an extra `\0`

2018-07-21 Thread mratsim
Corresponding bug: [https://github.com/nim-lang/Nim/issues/6541](https://github.com/nim-lang/Nim/issues/6541)

Re: string literals should not allocate; should allocate in ROM an extra `\0`

2018-07-21 Thread Araq
Yeah, we really need to fix that. :-)

Re: string literals should not allocate; should allocate in ROM an extra `\0`

2018-07-20 Thread lscrd
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"

Re: string literals should not allocate; should allocate in ROM an extra `\0`

2018-07-20 Thread Araq
> 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

Re: string literals should not allocate; should allocate in ROM an extra `\0`

2018-07-19 Thread timothee
> 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

string literals should not allocate; should allocate in ROM an extra `\0`

2018-07-19 Thread Araq
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

string literals should not allocate; should allocate in ROM an extra `\0`

2018-07-19 Thread RodSteward
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

string literals should not allocate; should allocate in ROM an extra `\0`

2018-07-19 Thread Araq
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.

string literals should not allocate; should allocate in ROM an extra `\0`

2018-07-19 Thread timothee
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(){