On 4/22/18 2:00 AM, WhatMeForget wrote:
Surely a stupid mistake on my part, but why is the first array repeated?
In addition to what Neia said, you shouldn't use pointers to dynamic
arrays. Such things are really hard to allocate on the heap, since new
int[] just makes an array,
On Sunday, 22 April 2018 at 06:00:15 UTC, WhatMeForget wrote:
foreach(i, elem; a)
{
int[] temp = new int[](5);
..
a[i] = &temp;
}
You're taking the address of a local variable and persisting it
beyond the variable's scope. This is not safe in general;
compilers
Surely a stupid mistake on my part, but why is the first array
repeated?
import std.stdio;
void main()
{
int[]*[2] a; // a static arrray holding pointers to dynamic
arrays
static int unique = 0;
foreach(i, elem; a)
{
int[] temp = new int[](5);
foreach(ref
On Monday, 17 August 2015 at 13:27:19 UTC, Brandon Ragland wrote:
If that is true, than passing it as _char[] file_ makes the
most sense to me. A pointer copy doesn't hurt as bad as an
array copy, of say, 100Kibibytes...
Right.
Knowing this helps to explain a lot btw:
char[] foo;
void func(
On Monday, 17 August 2015 at 03:07:26 UTC, Adam D. Ruppe wrote:
On Monday, 17 August 2015 at 02:45:22 UTC, Brandon Ragland
wrote:
[...]
Short answer: pointers to slices are usually a mistake, you
probably don't actually want it, but rather should be using a
regular slice instead.
[...]
On Monday, 17 August 2015 at 02:45:22 UTC, Brandon Ragland wrote:
Since Dynamic Arrays / Slices are a D feature, using pointers
to these has me a bit confused...
Short answer: pointers to slices are usually a mistake, you
probably don't actually want it, but rather should be using a
regular s
On Monday, 17 August 2015 at 02:45:22 UTC, Brandon Ragland wrote:
Howdy,
Since Dynamic Arrays / Slices are a D feature, using pointers
to these has me a bit confused...
Consider:
Now what is especially confusing about this, is that the above
seems to works fine, while this does not:
if(
On Monday, 17 August 2015 at 02:45:22 UTC, Brandon Ragland wrote:
if(file[(*pos + i)] == '}'){
*pos += i;
return;
}
That code doesn't do what you want it do. file is a ((char[])*)
you are indexing the pointer(accessing invalid memory) and
getting a char[].
Howdy,
Since Dynamic Arrays / Slices are a D feature, using pointers to
these has me a bit confused...
Consider:
string c2s(int* pos, char[]* file, int l){
char[] s;
for(int i = 0; i < l; i++){
s ~= file[(*pos + i)];
}
return s.dup;
}
Now what