Thread overview
cstrings
Jan 02, 2011
Ellery Newcomer
Jan 02, 2011
Jonathan M Davis
Jan 02, 2011
Mafi
January 02, 2011
are there any other cstring -> dstring functions than to!string(char*) ?

something like to!(char[])(char*)

(the memory allocation bothers me)
January 02, 2011
On Saturday 01 January 2011 20:12:31 Ellery Newcomer wrote:
> are there any other cstring -> dstring functions than to!string(char*) ?
> 
> something like to!(char[])(char*)
> 
> (the memory allocation bothers me)

to!(char[])() should work just fine, but I believe that you're going to have to have a memory allocation regardless, since a D array can't refer to an arbitrary pointer. A D array and a C/C++ array are two different different things, even though a D array uses a C/C++ array internally. A D array is able to be resized and reallocated and the like in a way that a C/C++ array can't be.

- Jonathan M Davis
January 02, 2011
Am 02.01.2011 05:12, schrieb Ellery Newcomer:
> are there any other cstring -> dstring functions than to!string(char*) ?
>
> something like to!(char[])(char*)
>
> (the memory allocation bothers me)

You can simply make a slice. Indexing and sclicing works also with c-style pointers in D. Obviously $ is not allowed because bare pointers don't have a length.
poinetr[0 .. strlen(pointer)]
Be sure to not give this array to functions which relies on your char[] to be GC-allocated.