On Saturday, 2 July 2016 at 21:23:57 UTC, Namespace wrote:
passing by value is only a good solution if your struct is
really small.
It's not uncommon for optimizers to generate the same code either
way regardless of what you write.
Just for you, a slightly adapted version:
import std.stdio;
struct A {
public int id = 0;
this(int id) {
this.id = id;
}
ref A byRef() {
return this;
}
}
void foo(ref const A a) {
writeln(a.id
On Saturday, 2 July 2016 at 21:19:04 UTC, ketmar wrote:
On Saturday, 2 July 2016 at 21:17:33 UTC, Namespace wrote:
On Saturday, 2 July 2016 at 21:15:29 UTC, ketmar wrote:
On Saturday, 2 July 2016 at 21:05:18 UTC, Namespace wrote:
Try this little trick:
or don't. such pointers to structs are
On Saturday, 2 July 2016 at 21:17:33 UTC, Namespace wrote:
On Saturday, 2 July 2016 at 21:15:29 UTC, ketmar wrote:
On Saturday, 2 July 2016 at 21:05:18 UTC, Namespace wrote:
Try this little trick:
or don't. such pointers to structs are *dangerous*.
Either that "dangerous" thing or 2^N templ
On Saturday, 2 July 2016 at 20:40:00 UTC, Adam D. Ruppe wrote:
Using ref is wasteful there regardless just take an
ordinary Point (even const is optional if it is all value but
it doesn't hurt).
I think a lot of C++ programmers overuse references. If you're
passing a large thing, it makes
On Saturday, 2 July 2016 at 21:15:29 UTC, ketmar wrote:
On Saturday, 2 July 2016 at 21:05:18 UTC, Namespace wrote:
Try this little trick:
or don't. such pointers to structs are *dangerous*.
Either that "dangerous" thing or 2^N template bloat.
On Saturday, 2 July 2016 at 21:05:18 UTC, Namespace wrote:
Try this little trick:
or don't. such pointers to structs are *dangerous*.
On Saturday, 2 July 2016 at 19:40:53 UTC, phant0m wrote:
On Saturday, 2 July 2016 at 19:25:37 UTC, ketmar wrote:
note the first "()", though: this is effectively a template
function, which compiler will instantiate either with "ref" or
without it.
Yeah, I've noticed it. Always using function
On Saturday, 2 July 2016 at 20:24:12 UTC, phant0m wrote:
I took a simple task (for D learning purposes): to implement a
Point template "class" (something like Qt's QPoint).
Using ref is wasteful there regardless just take an ordinary
Point (even const is optional if it is all value but it
On Saturday, 2 July 2016 at 19:46:53 UTC, Adam D. Ruppe wrote:
On Saturday, 2 July 2016 at 18:37:06 UTC, phant0m wrote:
How should I pass a struct variable in D effectively?
Passing by value is often the most efficient. It depends on
what exactly you have in the struct.
From the point of vi
On Saturday, 2 July 2016 at 18:37:06 UTC, phant0m wrote:
How should I pass a struct variable in D effectively?
Passing by value is often the most efficient. It depends on what
exactly you have in the struct.
On Saturday, 2 July 2016 at 19:25:37 UTC, ketmar wrote:
note the first "()", though: this is effectively a template
function, which compiler will instantiate either with "ref" or
without it.
Yeah, I've noticed it. Always using function template for this
use case seems like a weird idea.
On Saturday, 2 July 2016 at 18:47:31 UTC, phant0m wrote:
On Saturday, 2 July 2016 at 18:43:51 UTC, ketmar wrote:
void boo() (in auto ref MyStruct s) { ... }
this will accept both lvalues and rvalues, and will avoid
copying if it can.
Thank you! Could you please explain what does "auto" in th
On Sat, Jul 02, 2016 at 06:47:31PM +, phant0m via Digitalmars-d-learn wrote:
> On Saturday, 2 July 2016 at 18:43:51 UTC, ketmar wrote:
> > void boo() (in auto ref MyStruct s) { ... }
> >
> > this will accept both lvalues and rvalues, and will avoid copying if
> > it can.
>
> Thank you! Could
On Saturday, 2 July 2016 at 01:51:03 UTC, rikki cattermole wrote:
Couple of things could be happening.
1) Alignments are off, aligning of data really really matters
Where? I rewrote the code to use size_t and same problem. If
alignments were off chances are it wouldn't exhibit the issues in
th
On Saturday, 2 July 2016 at 18:43:51 UTC, ketmar wrote:
void boo() (in auto ref MyStruct s) { ... }
this will accept both lvalues and rvalues, and will avoid
copying if it can.
Thank you! Could you please explain what does "auto" in this
context mean?
void boo() (in auto ref MyStruct s) { ... }
this will accept both lvalues and rvalues, and will avoid copying
if it can.
I came from a C++ world, so I'm used to passing structs by a
const reference (I mean the case, where a function argument isn't
changed by the function). C++ allows passing a temporary (rvalue)
to a function, which accepts a const reference. D doesn't allow
this. All I have found is a message fr
On Saturday, 2 July 2016 at 03:54:26 UTC, Mike Parker wrote:
On Saturday, 2 July 2016 at 00:08:10 UTC, Hiemlick Hiemlicker
wrote:
I use a struct with static members so I do not have to
instantiate it. It is essentially a singleton. I want all the
variables to be __gshared. I guess I have to
On Saturday, 2 July 2016 at 12:10:28 UTC, qznc wrote:
I want to implement some caching for HTTP GET requests.
Basically a map of URL to content. A cache needs some
additional meta data (size, age, etc).
There seem to be two basic data structures available:
Associative array (AA) or red black
I want to implement some caching for HTTP GET requests. Basically
a map of URL to content. A cache needs some additional meta data
(size, age, etc).
There seem to be two basic data structures available: Associative
array (AA) or red black tree (RBT).
With AA cache eviction is inefficient. It
21 matches
Mail list logo