Using D1, I have a program that creates tons of float[] ; for performance
reasons, I would like them to be uninitialized.
I've tried replacing
float[] f = new float[x];
by
float[] f = cast(float[])std.gc.malloc(x*4);
Unfortunately I keep running into "Access violation" and sometimes "Array
bound
Bear:
> Using D1, I have a program that creates tons of float[] ; for performance
> reasons, I would like them to be uninitialized.
> I've tried replacing
>
> float[] f = new float[x];
> by
> float[] f = cast(float[])std.gc.malloc(x*4);
Try something like this (untested):
alias float TF;
TF[] f
Am 19.12.2011, 13:04 Uhr, schrieb Bear :
Using D1, I have a program that creates tons of float[] ; for performance
reasons, I would like them to be uninitialized.
std.array.uninitializedArray
On Mon, 19 Dec 2011 07:04:20 -0500, Bear wrote:
Using D1, I have a program that creates tons of float[] ; for performance
reasons, I would like them to be uninitialized.
I've tried replacing
float[] f = new float[x];
by
float[] f = cast(float[])std.gc.malloc(x*4);
this is wrong. a float[] s
gc.malloc actually returns void[]
Bearophile's suggestion seems to work though, but it doesn't seem to improve
performance for some reason... I guess I'll have to find some other way to make
my
prog quicker.
On 2011-12-19 18:24, Bear wrote:
gc.malloc actually returns void[]
Bearophile's suggestion seems to work though, but it doesn't seem to improve
performance for some reason... I guess I'll have to find some other way to make
my
prog quicker.
You can always make the variable uninitialized using
On Mon, 19 Dec 2011 12:24:18 -0500, Bear wrote:
gc.malloc actually returns void[]
http://www.d-programming-language.org/phobos/core_memory.html#malloc
Looks like void* to me...
Or is there another function I'm not aware of? I think it should be
GC.malloc, not gc.malloc, so maybe I'm miss
On Mon, 19 Dec 2011 18:52:44 +0100
Jacob Carlborg wrote:
> You can always make the variable uninitialized using "void", don't
> know if that what is what you're looking for.
>
> float[] f = void;
>
He is trying to create an array where the elements are not initialized.
On 2011-12-20 01:34, Jesse Phillips wrote:
On Mon, 19 Dec 2011 18:52:44 +0100
Jacob Carlborg wrote:
You can always make the variable uninitialized using "void", don't
know if that what is what you're looking for.
float[] f = void;
He is trying to create an array where the elements are not
On 19/12/2011 18:11, Steven Schveighoffer wrote:
On Mon, 19 Dec 2011 12:24:18 -0500, Bear wrote:
gc.malloc actually returns void[]
http://www.d-programming-language.org/phobos/core_memory.html#malloc
Looks like void* to me...
Or is there another function I'm not aware of? I think it should
On 19/12/2011 12:12, bearophile wrote:
Bear:
float[] f = cast(float[])std.gc.malloc(x*4);
Try something like this (untested):
alias float TF;
TF[] f = (cast(TF*)std.gc.malloc(x * TF.sizeof))[0 .. x];
I fail to see any real difference from the OP's code:
- Why the alias?
- std.gc.malloc
On Tue, 20 Dec 2011 09:22:46 -0500, Stewart Gordon
wrote:
On 19/12/2011 18:11, Steven Schveighoffer wrote:
On Mon, 19 Dec 2011 12:24:18 -0500, Bear wrote:
gc.malloc actually returns void[]
http://www.d-programming-language.org/phobos/core_memory.html#malloc
Looks like void* to me...
O
On 12/19/2011 01:04 PM, Bear wrote:
Using D1, I have a program that creates tons of float[] ; for performance
reasons, I would like them to be uninitialized.
I've tried replacing
float[] f = new float[x];
by
float[] f = cast(float[])std.gc.malloc(x*4);
Unfortunately I keep running into "Access
Stewart Gordon:
> On 19/12/2011 12:12, bearophile wrote:
> > Try something like this (untested):
> >
> > alias float TF;
> > TF[] f = (cast(TF*)std.gc.malloc(x * TF.sizeof))[0 .. x];
>
>
> I fail to see any real difference from the OP's code:
>
> - Why the alias?
Because in that code I have u
On 12/20/2011 07:12 PM, bearophile wrote:
Stewart Gordon:
On 19/12/2011 12:12, bearophile wrote:
Try something like this (untested):
alias float TF;
TF[] f = (cast(TF*)std.gc.malloc(x * TF.sizeof))[0 .. x];
I fail to see any real difference from the OP's code:
- Why the alias?
Because
On 20/12/2011 18:12, bearophile wrote:
Because in that code I have used three times a type (TF), auto allows to remove
only
one of them. The alias is not the best solution (a better solution is to put
that code
into a templated function), but repeating the same generic type more than one
time
Stewart Gordon:
> I don't quite understand - why not just use float as it is? OK, so
> abbreviating it to TF
> saves 9 characters on that line, but the alias declaration and its trailing
> line break
> take up 16 characters, so you're not saving space at all.
It's not a way to save chars, it'
On 20/12/2011 22:19, bearophile wrote:
That's also why I have said a better solution is to wrap that code into a
function
template, so there is no need for an alias.
So what you actually meant was to make TF a template parameter? That would
make more sense.
I can understand an alias being
Hey,
just wanted to know whether something like this would be possible
sowmehow:
struct S
{
int m;
int n;
this(this)
{
m = void;
n = n;
}
}
So not the whole struct is moved everytime f.e. a function is
called, but only n has to be "filled"
import std.stdio;
struct S {
int i;
int j;
}
int main(string[] args) {
S[] ss = void;
ss.length = 5;
foreach (ref s; ss)
s = S(1, 2);
return 0;
}
Is the above code correct? (it doesn't work... it blows away or just
give and access
On Sunday, 30 July 2017 at 19:22:07 UTC, Jiyan wrote:
Hey,
just wanted to know whether something like this would be
possible sowmehow:
struct S
{
int m;
int n;
this(this)
{
m = void;
n = n;
}
}
So not the whole struct is moved everytime f.e. a function is
called, but only n has to be "filled
On Sunday, 30 July 2017 at 19:32:48 UTC, Eugene Wissner wrote:
On Sunday, 30 July 2017 at 19:22:07 UTC, Jiyan wrote:
Hey,
just wanted to know whether something like this would be
possible sowmehow:
struct S
{
int m;
int n;
this(this)
{
m = void;
n = n;
}
}
So not the whole struct is moved ev
On Sunday, 30 July 2017 at 19:22:07 UTC, Jiyan wrote:
Hey,
just wanted to know whether something like this would be
possible sowmehow:
struct S
{
int m;
int n;
this(this)
{
m = void;
n = n;
}
}
So not the whole struct is moved everytime f.e. a function is
called, but only n has to be "filled
On 03/08/2011 01:34 PM, Tom wrote:
import std.stdio;
struct S {
int i;
int j;
}
int main(string[] args) {
S[] ss = void;
ss.length = 5;
foreach (ref s; ss)
s = S(1, 2);
return 0;
}
Is the above code correct? (it doesn't work... it blows away or just
give and access violation error).
I need to
On Tue, 08 Mar 2011 16:53:08 -0500, Ali Çehreli wrote:
On 03/08/2011 01:34 PM, Tom wrote:
import std.stdio;
struct S {
int i;
int j;
}
int main(string[] args) {
S[] ss = void;
ss.length = 5;
foreach (ref s; ss)
s = S(1, 2);
return 0;
}
Is the above code correct? (it doesn't work... it blows
On 03/08/2011 02:03 PM, Steven Schveighoffer wrote:
> it's not std.array.reserve, it's object.reserve, always present, no need
> to import.
Thanks. The reserve that I found in array.d is
std.array.Appender(T).reserve.
Ali
El 08/03/2011 19:03, Steven Schveighoffer escribió:
On Tue, 08 Mar 2011 16:53:08 -0500, Ali Çehreli wrote:
On 03/08/2011 01:34 PM, Tom wrote:
import std.stdio;
struct S {
int i;
int j;
}
int main(string[] args) {
S[] ss = void;
ss.length = 5;
foreach (ref s; ss)
s = S(1, 2);
return 0;
}
Is
On Tue, 08 Mar 2011 17:48:37 -0500, Tom wrote:
http://d.puremagic.com/issues/show_bug.cgi?id=5603
This is really sad. This kind of stuff is a must for performance. D is
disappointing me too much yet :(
There is always c's malloc, or you can try using the GC malloc directly.
For applic
On 03/08/2011 11:57 PM, Steven Schveighoffer wrote:
On Tue, 08 Mar 2011 17:48:37 -0500, Tom wrote:
http://d.puremagic.com/issues/show_bug.cgi?id=5603
This is really sad. This kind of stuff is a must for performance. D is
disappointing me too much yet :(
There is always c's malloc, or you c
On 03/08/2011 02:34 PM, Tom wrote:
import std.stdio;
struct S {
int i;
int j;
}
int main(string[] args) {
S[] ss = void;
ss.length = 5;
foreach (ref s; ss)
s = S(1, 2);
return 0;
}
Is the above code correct? (it doesn't work... it blows away or just
give and access violation error).
I need to
On 03/08/2011 05:42 PM, Kai Meyer wrote:
On 03/08/2011 02:34 PM, Tom wrote:
import std.stdio;
struct S {
int i;
int j;
}
int main(string[] args) {
S[] ss = void;
ss.length = 5;
foreach (ref s; ss)
s = S(1, 2);
return 0;
}
Is the above code correct? (it doesn't work... it blows away or just
gi
El 08/03/2011 21:42, Kai Meyer escribió:
On 03/08/2011 02:34 PM, Tom wrote:
import std.stdio;
struct S {
int i;
int j;
}
int main(string[] args) {
S[] ss = void;
ss.length = 5;
foreach (ref s; ss)
s = S(1, 2);
return 0;
}
Is the above code correct? (it doesn't work... it blows away or just
gi
This is probably going a bit above my head, but
"the existence of alignment holes in the objects is accounted for, usually by
setting them all to 0 upon initialization"
I suspect this isn't the case for void initialization; if my struct has some
alignment hole I better not voi
strtr:
> I suspect this isn't the case for void initialization; if my struct has some
> alignment hole I better not void initialize it if ever I want to compare it
> with somthing.
> Is this correct?
That has to be correct.
> Would you ever have an alignment hole if all
Hello Strtr,
Would you ever have an alignment hole if all the struct contains are
basic types(excluding bool)?
real, char[n], byte[n] and short[m] (for n%4 != 0 and m%2 != 0) might be
an issue.
--
... <
BCS Wrote:
> Hello Strtr,
>
> > Would you ever have an alignment hole if all the struct contains are
> > basic types(excluding bool)?
>
> real, char[n], byte[n] and short[m] (for n%4 != 0 and m%2 != 0) might be
> an issue.
>
Sounds logical, thanks!
Hello Strtr,
BCS Wrote:
Hello Strtr,
Would you ever have an alignment hole if all the struct contains are
basic types(excluding bool)?
real, char[n], byte[n] and short[m] (for n%4 != 0 and m%2 != 0) might
be an issue.
Sounds logical, thanks!
I don't actually *know* those will be a pro
bearophile Wrote:
> strtr:
>
> > I suspect this isn't the case for void initialization; if my struct has
> > some alignment hole I better not void initialize it if ever I want to
> > compare it with something.
> > Is this correct?
>
> That has to be
Hello Strtr,
Suppose I'd still would like to use void optimizations, how do you
clear the holes manually?
IIRC zero filling a block is likely cheaper that zero filling holes in it.
I'd avoid "=void" unless you know you will be copying structs into the space
(that will copy the holes as well
BCS Wrote:
> IIRC zero filling a block is likely cheaper that zero filling holes in it.
> I'd avoid "=void" unless you know you will be copying structs into the space
> (that will copy the holes as well).
And unless you will never compare the struct, as the garbage bits will also be
compared.
I
the
program. But I suggest you to avoid it when possible. You have to be careful,
because they can contain spurious pointers, that the conservative GC will use
to keep objects alive. This happens especially if the struct contains pointers
in the first place.
>I suspect this isn't the
The situation is ugly, see the post in the main newsgroup:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=107153
Bye,
bearophile
strtr:
> static if( S.sizeof == members.sizeof )
> S s = void;
> else
> S s;
You can use something like this :-)
import std.stdio: writeln;
int unusedBytesStruct(S)() if (is(S == struct)) {
int totUsed;
foreach (field; S.init.tupleof)
totUsed += field.sizeof;
return cast(in
Hi,
Chapter 12.15.2 of the spec explains that void initialization of
a static array can be faster than default initialization. This
seems logical because the array entries don't need to be set to
NaN. However, when I ran some tests for my matrix implementation,
it seemed that the de
One correction: I think you mean "using" a default-initialized array is
faster (not the initialization itself).
Another observation: dmd -O makes both cases slower! Hm?
Ali
On Friday, 8 November 2019 at 16:49:37 UTC, wolframw wrote:
I compiled with dmd -O -inline -release -noboundscheck
-mcpu=avx2 and ran the tests with the m array being
default-initialized in one run and void-initialized in another
run.
The results:
Default-initialized: 245 ms, 495 μs, and 2 hns
46 matches
Mail list logo