Re: static __gshared struct

2016-07-01 Thread Mike Parker via Digitalmars-d-learn
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 prefix all variables with it? Basically I have Foo.i; on

Re: static __gshared struct

2016-07-01 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 2 July 2016 at 00:08:10 UTC, Hiemlick Hiemlicker wrote: On Friday, 1 July 2016 at 23:36:35 UTC, Basile B. wrote: On Friday, 1 July 2016 at 23:26:19 UTC, Hiemlick Hiemlicker wrote: On Friday, 1 July 2016 at 23:03:17 UTC, Basile B. wrote: [...] Ok, Does that mean [...]

Re: Thunking problems with arch issues

2016-07-01 Thread rikki cattermole via Digitalmars-d-learn
Couple of things could be happening. 1) Alignments are off, aligning of data really really matters when dealing with executable code. 2) For Windows only. Don't forget to call FlushInstructionCache. Before executing.

Re: Does D has any support for thunks?

2016-07-01 Thread Hiemlick Hiemlicker via Digitalmars-d-learn
On Saturday, 25 June 2016 at 17:52:48 UTC, Andre Pany wrote: On Saturday, 25 June 2016 at 17:26:03 UTC, Andre Pany wrote: On Saturday, 25 June 2016 at 16:05:30 UTC, Vladimir Panteleev wrote: On Saturday, 25 June 2016 at 13:44:48 UTC, Andre Pany wrote: Does D/Phobos has any support for thunks?

Thunking problems with arch issues

2016-07-01 Thread Hiemlick Hiemlicker via Digitalmars-d-learn
The following code works on dmd x64. Fails on dmd x32 and ldc x64. The problem is the passed variable. import std.stdio; version (Windows) { import core.sys.windows.windows; void makeExecutable(ubyte[] code) { DWORD old; VirtualProtect(code.ptr, code.length,

Re: static __gshared struct

2016-07-01 Thread Hiemlick Hiemlicker via Digitalmars-d-learn
On Friday, 1 July 2016 at 23:36:35 UTC, Basile B. wrote: On Friday, 1 July 2016 at 23:26:19 UTC, Hiemlick Hiemlicker wrote: On Friday, 1 July 2016 at 23:03:17 UTC, Basile B. wrote: On Friday, 1 July 2016 at 22:47:21 UTC, Hiemlick Hiemlicker wrote: Ok, Does that mean void main() {

Re: static __gshared struct

2016-07-01 Thread Basile B. via Digitalmars-d-learn
On Friday, 1 July 2016 at 23:26:19 UTC, Hiemlick Hiemlicker wrote: On Friday, 1 July 2016 at 23:03:17 UTC, Basile B. wrote: On Friday, 1 July 2016 at 22:47:21 UTC, Hiemlick Hiemlicker wrote: Ok, Does that mean void main() { static struct Foo{} foo(); } void foo() { Foo f; }

Re: static __gshared struct

2016-07-01 Thread Hiemlick Hiemlicker via Digitalmars-d-learn
On Friday, 1 July 2016 at 23:03:17 UTC, Basile B. wrote: On Friday, 1 July 2016 at 22:47:21 UTC, Hiemlick Hiemlicker wrote: what exactly does this do? are all members _gshared? In this case __gshared is a complete NOOP. __gshared has only an effect on variables. It prevents them to reside in

Re: static __gshared struct

2016-07-01 Thread Basile B. via Digitalmars-d-learn
On Friday, 1 July 2016 at 22:47:21 UTC, Hiemlick Hiemlicker wrote: what exactly does this do? are all members _gshared? In this case __gshared is a complete NOOP. __gshared has only an effect on variables. It prevents them to reside in the TLS, so that they can be used by any thread of the

static __gshared struct

2016-07-01 Thread Hiemlick Hiemlicker via Digitalmars-d-learn
what exactly does this do? are all members _gshared?

Re: Get program stats at run time

2016-07-01 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 30 June 2016 at 21:56:57 UTC, Special opOps wrote: How can I get the program stats at run time such as minimum and maximum amount of memory and cpu used, cpu architecture, os, etc? OS is compile-time constant. http://dlang.org/phobos/std_system.html#.os Or do you look for

Re: Casting classes

2016-07-01 Thread Jonathan Marler via Digitalmars-d-learn
On Friday, 1 July 2016 at 17:34:25 UTC, Basile B. wrote: On Friday, 1 July 2016 at 17:32:26 UTC, Basile B. wrote: On Friday, 1 July 2016 at 15:45:35 UTC, Jonathan Marler wrote: How do casts work under the hood? I'm mostly interested in what needs to be done in order to cast a class to a

Re: Casting classes

2016-07-01 Thread Basile B. via Digitalmars-d-learn
On Friday, 1 July 2016 at 17:32:26 UTC, Basile B. wrote: On Friday, 1 July 2016 at 15:45:35 UTC, Jonathan Marler wrote: How do casts work under the hood? I'm mostly interested in what needs to be done in order to cast a class to a subclass. I'd like to know what is being done to determine

Re: Casting classes

2016-07-01 Thread Basile B. via Digitalmars-d-learn
On Friday, 1 July 2016 at 15:45:35 UTC, Jonathan Marler wrote: How do casts work under the hood? I'm mostly interested in what needs to be done in order to cast a class to a subclass. I'd like to know what is being done to determine whether the object is a valid instance of the cast type.

Casting classes

2016-07-01 Thread Jonathan Marler via Digitalmars-d-learn
How do casts work under the hood? I'm mostly interested in what needs to be done in order to cast a class to a subclass. I'd like to know what is being done to determine whether the object is a valid instance of the cast type. If the code is implemented in the druntime, a pointer to where

Re: Associative array of const items

2016-07-01 Thread Jonathan Marler via Digitalmars-d-learn
On Friday, 1 July 2016 at 06:57:59 UTC, QAston wrote: On Thursday, 30 June 2016 at 17:08:45 UTC, Jonathan Marler wrote: Is there a way to have an associative array of const values? I thought it would have been: const(T)[K] map; map[x] = y; but the second line gives Error: cannot modify const

Re: Get current date and time with std.datetime

2016-07-01 Thread Zekereth via Digitalmars-d-learn
On Thursday, 30 June 2016 at 21:18:22 UTC, Luke Picardo wrote: Why is it so hard to simply get the current date and time formatted properly in a string? There are no examples of this in your documentation yet this is probably one of the most used cases. To get the current time, use

Re: Range non-emptyness assertions and opIndex

2016-07-01 Thread Nordlöw via Digitalmars-d-learn
On Friday, 1 July 2016 at 11:35:40 UTC, ag0aep6g wrote: Huh? Asserts are ignored with -release. The only exception is assert(false) which terminates the program immediately, even with -release. Aha, that's what I was testing against so therefore the confusion.

Re: Range non-emptyness assertions and opIndex

2016-07-01 Thread Rene Zwanenburg via Digitalmars-d-learn
On Friday, 1 July 2016 at 10:35:04 UTC, Nordlöw wrote: I think this is a important issue since asserts are not optimized away in release mode and D is very much about performance. Asserts are removed in release mode, enforce isn't. Here's an example: = void main(string[] args) {

Re: Range non-emptyness assertions and opIndex

2016-07-01 Thread ag0aep6g via Digitalmars-d-learn
On 07/01/2016 12:35 PM, Nordlöw wrote: What's the preferred way of reacting to emptyness in the members front, back, popFront, popBack --- using assert, enforce, throw, or simply relying on range-checking in the _store? I think assert is the most common way of checking. Simply ignoring the

Range non-emptyness assertions and opIndex

2016-07-01 Thread Nordlöw via Digitalmars-d-learn
If I have a typical range definition like the following struct Range { @safe pure @nogc: bool empty() const nothrow { return _i == _j; } size_t length() const nothrow { return _j - _i; } bool

some atomic structs

2016-07-01 Thread jj75607 via Digitalmars-d-learn
I wrote some java-like atomic structs. Please criticize it https://dpaste.dzfl.pl/24f1438ebb52

Re: Associative array of const items

2016-07-01 Thread QAston via Digitalmars-d-learn
On Thursday, 30 June 2016 at 17:08:45 UTC, Jonathan Marler wrote: Is there a way to have an associative array of const values? I thought it would have been: const(T)[K] map; map[x] = y; but the second line gives Error: cannot modify const expression. I would think that the const(T)[K] would