On Monday, 23 January 2017 at 06:42:00 UTC, Suliman wrote:
You have *two* distinct strings here.
Yes, I understand, I am trying to find out how it's work on low
level. Any ideas why zero is used?
string *literals* in d are nul terminated to ease interoperation
with C
so
string s = "foo";
You have *two* distinct strings here.
Yes, I understand, I am trying to find out how it's work on low
level. Any ideas why zero is used?
I'm not sure if it's what happening in this case but, in code
as simple as this, function calls can sometimes be the
bottleneck. You should see how compiling with/without -O
affects performance, and adding `pragma(inline)` to funcB.
I guess my question is whether it is possible to have meaning
On Monday, 23 January 2017 at 02:20:02 UTC, Nestor wrote:
On Monday, 23 January 2017 at 01:17:20 UTC, Adam D. Ruppe wrote:
On Monday, 23 January 2017 at 01:12:21 UTC, Nestor wrote:
You mean phobos, or system libraries?
Phobos but mostly the druntime that interfaces with the system.
I see, I
On 23/01/2017 3:20 PM, Nestor wrote:
On Monday, 23 January 2017 at 01:17:20 UTC, Adam D. Ruppe wrote:
On Monday, 23 January 2017 at 01:12:21 UTC, Nestor wrote:
You mean phobos, or system libraries?
Phobos but mostly the druntime that interfaces with the system.
I see, I was mostly thinking
On Sunday, 22 January 2017 at 15:59:47 UTC, Suliman wrote:
On Sunday, 22 January 2017 at 15:51:01 UTC, Suliman wrote:
string str = "abc";
writeln(str.ptr);
str = "def";
writeln("last data: ", *(str.ptr));
writeln("old data: ", *(str.ptr-1)); // print nothi
On Monday, 23 January 2017 at 01:17:20 UTC, Adam D. Ruppe wrote:
On Monday, 23 January 2017 at 01:12:21 UTC, Nestor wrote:
You mean phobos, or system libraries?
Phobos but mostly the druntime that interfaces with the system.
I see, I was mostly thinking in Android and/or other platforms,
bu
On Monday, 23 January 2017 at 01:12:21 UTC, Nestor wrote:
You mean phobos, or system libraries?
Phobos but mostly the druntime that interfaces with the system.
On Saturday, 21 January 2017 at 19:33:27 UTC, Adam D. Ruppe wrote:
On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote:
That would be cool for greater portability.
The hard part in porting to a new platform is rarely the code
generation - gdc and ldc have diverse backends already (inde
I've been increasingly using output ranges in my code (the
"component programming" model described in several articles on
the D site). It works very well, except that it would often be
more convenient to use writeln style functions rather than 'put'.
Especially when you start by drafting a sket
On Sunday, 22 January 2017 at 15:51:01 UTC, Suliman wrote:
string str = "abc";
writeln(str.ptr);
str = "def";
writeln("last data: ", *(str.ptr));
writeln("old data: ", *(str.ptr-1)); // print nothing
writeln("old data: ", *(str.ptr-2)); // print c
string str = "abc";
writeln(str.ptr);
str = "def";
writeln("last data: ", *(str.ptr));
writeln("old data: ", *(str.ptr-1)); // print nothing
writeln("old data: ", *(str.ptr-2)); // print c
It's look like that there is some gap between data, because
Supported answer: you don't, it has infinite lifetime and
you're claiming it is immutable, but then trying to pull the
memory out from under it! The supported solution is simply to
let the garbage collector manage it.
But..
//GC.free(str_ptr.ptr); // Error: function
core.memory.GC.free (
On Sunday, 22 January 2017 at 14:04:55 UTC, Suliman wrote:
So str.ptr is just shortcut?
str.ptr is the actual member. In D, pointers to structs (and an
array is virtually the same as a struct) will automatically
dereference themselves.
T* t;
t.member; // automatically rewritten into (*t).me
str_ptr.ptr returns exactly the same thing as str.ptr or
(*str_ptr).ptr, a pointer to the contents. When you write
str_ptr, you print the pointer to the container.
So str.ptr is just shortcut?
Ok, but how to free memory from first located value (from `aaa`)?
I changed my code to next:
import
On Sunday, 22 January 2017 at 12:49:11 UTC, Suliman wrote:
writeln(str_ptr);
writeln("before dealloc: ", str_ptr.length);
GC.free(str_ptr.ptr);
writeln(str_ptr);
You freed the CONTENTS, but are printing the CONTAINER.
str_ptr.ptr returns exactly the same thing as str.p
On Sunday, 22 January 2017 at 13:34:10 UTC, Suliman wrote:
str[] = ""[];
That means copy the contents of the right hand array into the
location of the left hand array.
It copies data, that operation will never change pointers.
str = "";
would change the pointer.
You do not append to anything, only overwrite it. There is no
reallocation because
"aaa".length == "bbb".length.
I changed my code to:
str_ptr.length +=1;
str[] = ""[];
But now it's print length 4 before and after writing "bbb" to
`str`. I expected that size will be 3+4=7.
On Sunday, 22 January 2017 at 12:49:11 UTC, Suliman wrote:
import std.stdio;
import std.string;
import core.memory;
void main()
{
char [] str = "aaa".dup;
char [] *str_ptr = &str;
writeln("before: ", str_ptr.ptr);// address of structure
writeln(*str_ptr.ptr); // address of data
import std.stdio;
import std.string;
import core.memory;
void main()
{
char [] str = "aaa".dup;
char [] *str_ptr = &str;
writeln("before: ", str_ptr.ptr);// address of structure
writeln(*str_ptr.ptr); // address of data
str[] = "bbb"[]; // now writing to structure new data, s
On Sunday, 22 January 2017 at 08:18:35 UTC, Jot wrote:
On Sunday, 22 January 2017 at 08:07:26 UTC, rikki cattermole
wrote:
On 22/01/2017 9:05 PM, Jot wrote:
auto x = new int[][](n,m);
But one cannot freely assign anywhere in x:
x[3,6] = 4 crashes.
I, can, of course, convert everything to a l
In anycase, what is the correct notation for indexing?
x = new int[][](width, height)
and x[height][width] or x[width][height]?
It's x[width][height], but because indexing is 0-based, largest
valid indexes are
x[width-1][height-1].
On Sunday, 22 January 2017 at 08:07:26 UTC, rikki cattermole
wrote:
On 22/01/2017 9:05 PM, Jot wrote:
auto x = new int[][](n,m);
But one cannot freely assign anywhere in x:
x[3,6] = 4 crashes.
I, can, of course, convert everything to a linear matrix and
index by
i+w*j, but what's the point o
Trying to get a dub sub package to output as a shared lib but for
some reason I can only get it to output as a static lib.
dub.json
---
{
"name": "tofueng",
"targetType": "executable",
"targetPath" : "game",
"sourcePaths": ["eng"],
"importPaths": ["eng"],
On 22/01/2017 9:05 PM, Jot wrote:
auto x = new int[][](n,m);
But one cannot freely assign anywhere in x:
x[3,6] = 4 crashes.
I, can, of course, convert everything to a linear matrix and index by
i+w*j, but what's the point of having multidimensional matrices in D if
they don't allocate them fu
auto x = new int[][](n,m);
But one cannot freely assign anywhere in x:
x[3,6] = 4 crashes.
I, can, of course, convert everything to a linear matrix and
index by i+w*j, but what's the point of having multidimensional
matrices in D if they don't allocate them fully?
26 matches
Mail list logo