Re: cannot modify struct with immutable members

2015-01-02 Thread ketmar via Digitalmars-d-learn
On Sat, 03 Jan 2015 16:40:14 +1030 ted via Digitalmars-d-learn wrote: > I'm now taking the view that const is there for the compiler to optimise > code on the basis that nothing can alter it once set (and can only be set > on initialisation). So I see your point that it would not be used very

Re: cannot modify struct with immutable members

2015-01-02 Thread ted via Digitalmars-d-learn
ketmar via Digitalmars-d-learn wrote: > On Sat, 03 Jan 2015 15:56:58 +1030 > ted via Digitalmars-d-learn wrote: > >> Ironically, I'm trying to use const in an effort to understand it...but >> there seems to be an unusual amount of pain until I grok it. > just remember that `const` "infects" ever

Re: cannot modify struct with immutable members

2015-01-02 Thread ketmar via Digitalmars-d-learn
On Sat, 03 Jan 2015 15:56:58 +1030 ted via Digitalmars-d-learn wrote: > Ironically, I'm trying to use const in an effort to understand it...but > there seems to be an unusual amount of pain until I grok it. just remember that `const` "infects" everything down to the bytes when it's applied. and

Re: cannot modify struct with immutable members

2015-01-02 Thread ted via Digitalmars-d-learn
ketmar via Digitalmars-d-learn wrote: > On Sat, 03 Jan 2015 14:45:24 +1030 > ted via Digitalmars-d-learn wrote: > >> Well, I just cleared up some of my misunderstanding. >> >> I did not realise the mA (within struct Test) would be a _copy_ of arg, >> not a reference (pointer) to arg. >> >> So

Re: cannot modify struct with immutable members

2015-01-02 Thread ketmar via Digitalmars-d-learn
On Sat, 03 Jan 2015 14:45:24 +1030 ted via Digitalmars-d-learn wrote: p.s. also please note that structs in D are always passed by value and copied (until you not explicitly ask for something another). so: MyStruct a; MyStruct b; b = a; actually does `memcpy()` (with postblit if there is

Re: cannot modify struct with immutable members

2015-01-02 Thread ketmar via Digitalmars-d-learn
On Sat, 03 Jan 2015 14:45:24 +1030 ted via Digitalmars-d-learn wrote: > Well, I just cleared up some of my misunderstanding. > > I did not realise the mA (within struct Test) would be a _copy_ of arg, not > a reference (pointer) to arg. > > So the more correct code snippet would be: > > stru

Re: cannot modify struct with immutable members

2015-01-02 Thread ted via Digitalmars-d-learn
Well, I just cleared up some of my misunderstanding. I did not realise the mA (within struct Test) would be a _copy_ of arg, not a reference (pointer) to arg. So the more correct code snippet would be: struct A { int someInt; } struct Test { @property { const(A) getA() { return *mA;

Re: cannot modify struct with immutable members

2015-01-02 Thread ted via Digitalmars-d-learn
Hi, thanks for the reply...to answer your direct question, the original code looked like: struct A { int someInt; } struct Test { @property { const(A) getA() { return mA; } } this( ref const(A) arg ) { mA = arg; } private: A mA; } void main() { Test myTest

Re: cannot modify struct with immutable members

2015-01-02 Thread ketmar via Digitalmars-d-learn
On Sat, 03 Jan 2015 13:25:31 +1030 ted via Digitalmars-d-learn wrote: > > I get the following error from the code below: (dmd2.066.1, linux) > test.d(26): Error: cannot modify struct myTest1 Test with immutable members > > Is this expected? > > If so, how can I achieve this result - being able

cannot modify struct with immutable members

2015-01-02 Thread ted via Digitalmars-d-learn
I get the following error from the code below: (dmd2.066.1, linux) test.d(26): Error: cannot modify struct myTest1 Test with immutable members Is this expected? If so, how can I achieve this result - being able to set (a new) initial value of myTest1 from within an nested function ? thanks ! t

Re: What exactly shared means?

2015-01-02 Thread Peter Alexander via Digitalmars-d-learn
On Friday, 2 January 2015 at 23:51:05 UTC, John Colvin wrote: The rule (in C(++) at least) is that all data is assumed to be visible and mutable from multiple other threads unless proved otherwise. However, given that you do not write a race, the compiler will provide full sequential consistenc

Re: What exactly shared means?

2015-01-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 02, 2015 23:51:04 John Colvin via Digitalmars-d-learn wrote: > AFAIK, the only data in D that the compiler is allowed to assume > to be thread-local is data that it can prove is thread-local. The > trivial case is TLS, which is thread-local by definition. In D, if a type is not

Re: What exactly shared means?

2015-01-02 Thread via Digitalmars-d-learn
On Friday, 2 January 2015 at 23:10:46 UTC, John Colvin wrote: What significant optimisations does SC-DRF actually prevent? By "SC-DRF" I assume you mean the Java memory model. AFAIK SCDRF just means that if you syncronize correctly (manually) then you will get sequential consistency (restrict

Re: What exactly shared means?

2015-01-02 Thread John Colvin via Digitalmars-d-learn
On Friday, 2 January 2015 at 23:26:57 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: On Friday, January 02, 2015 19:47:50 John Colvin via Digitalmars-d-learn wrote: On Friday, 2 January 2015 at 13:14:14 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: > Objects in D default to being th

Re: What exactly shared means?

2015-01-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 02, 2015 15:32:51 Steven Schveighoffer via Digitalmars-d-learn wrote: > In fact the > only useful aspect of shared is that data not marked as shared is > guaranteed thread local. That and the fact that you're supposed to be able to know which portions of your program are operat

Re: What exactly shared means?

2015-01-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 02, 2015 19:47:50 John Colvin via Digitalmars-d-learn wrote: > On Friday, 2 January 2015 at 13:14:14 UTC, Jonathan M Davis via > Digitalmars-d-learn wrote: > > Objects in D default to being thread-local. __gshared and > > shared both make > > it so that they're not thread-local.

Re: What exactly shared means?

2015-01-02 Thread John Colvin via Digitalmars-d-learn
On Friday, 2 January 2015 at 22:10:36 UTC, Ola Fosheim Grøstad wrote: On Friday, 2 January 2015 at 21:06:03 UTC, John Colvin wrote: Hmm. I went in to writing that thinking "shared isn't so bad". Now I've thought about it, it is pretty damn useless. What's the point of knowing that data is share

Re: What exactly shared means?

2015-01-02 Thread via Digitalmars-d-learn
On Friday, 2 January 2015 at 21:06:03 UTC, John Colvin wrote: Hmm. I went in to writing that thinking "shared isn't so bad". Now I've thought about it, it is pretty damn useless. What's the point of knowing that data is shared without knowing how to safely use it? I guess it protects against co

Re: What exactly shared means?

2015-01-02 Thread John Colvin via Digitalmars-d-learn
On Friday, 2 January 2015 at 20:32:51 UTC, Steven Schveighoffer wrote: On 1/2/15 2:47 PM, John Colvin wrote: Are you sure about all this optimisation stuff? I had (perhaps wrongly) assumed that __gshared and shared variables in D guaranteed Sequential Consistency for Data Race Free (SCDRF) a

Re: How to create instance of class that get data from 2 another instance?

2015-01-02 Thread Suliman via Digitalmars-d-learn
Oh mama mia! I did it! http://www.everfall.com/paste/id.php?a5pp73ns1e4k auto seismodownload = new seismoDownload(emsc_csem, this); then: auto mysql = new MySQL(parseconfig,eqs); So could anybody show me better way? As I said I did not fully understand how use global class instance...

Re: What exactly shared means?

2015-01-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/2/15 2:47 PM, John Colvin wrote: Are you sure about all this optimisation stuff? I had (perhaps wrongly) assumed that __gshared and shared variables in D guaranteed Sequential Consistency for Data Race Free (SCDRF) and nothing more, just like all normal variables in C, C++ and Java. Ther

Re: What exactly shared means?

2015-01-02 Thread John Colvin via Digitalmars-d-learn
On Friday, 2 January 2015 at 13:14:14 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: Objects in D default to being thread-local. __gshared and shared both make it so that they're not thread-local. __gshared does it without actually changing the type, making it easier to use but also danger

Re: Example usage of the core.sync classes

2015-01-02 Thread Benjamin Thaut via Digitalmars-d-learn
Am 02.01.2015 um 19:45 schrieb Vlad Levenfeld: My personal favorite method is to use the primitives in core.atomic with a double or triple buffer. To double buffer, keep two buffers in an array (data[][] or something) and an integer index that points to the active buffer, then use atomicStore to

Re: Example usage of the core.sync classes

2015-01-02 Thread Vlad Levenfeld via Digitalmars-d-learn
On Friday, 2 January 2015 at 17:39:19 UTC, Matt wrote: I'm trying to write a small 3D engine, and wanted to place the physics in a separate thread to the graphics, using events, possibly std.concurrency, to communicate between them. How, then, do I pass large amounts of data between threads? I

vibe.d + dub dynamic library

2015-01-02 Thread Benjamin Thaut via Digitalmars-d-learn
Is it possible to get dub to build vibe.d into a dynamic library? Or is it at least possible to make dub link against the shared version of phobos? I found this blog post about dynamic linktimes, unfortunately it does not describe how to actually make dub use the dynamic version of phobos. htt

Example usage of the core.sync classes

2015-01-02 Thread Matt via Digitalmars-d-learn
I'm trying to write a small 3D engine, and wanted to place the physics in a separate thread to the graphics, using events, possibly std.concurrency, to communicate between them. How, then, do I pass large amounts of data between threads? I'm thinking the physics world state (matrix for each ob

Re: How to create instance of class that get data from 2 another instance?

2015-01-02 Thread Suliman via Digitalmars-d-learn
class parseConfig { string dbname; string dbuser; string dbpass; string dbhost; string dbport; uint status; this() { auto checkLinkCode(string link) // we need to check all links to be sure if they are alive { return

vibe.d mongodb connections

2015-01-02 Thread Benjamin Thaut via Digitalmars-d-learn
I'm currently trying around with vibe.d and I'm confused about the MongoDB example: import vibe.d; MongoClient client; void test() { auto coll = client.getCollection("test.collection"); foreach (doc; coll.find(["name": "Peter"])) logInfo("Found entry: %s", doc.t

Re: How to create instance of class that get data from 2 another instance?

2015-01-02 Thread Suliman via Digitalmars-d-learn
I think it's fine to have a global config instance. Alternatively you can pass the config to both the seismoDownlead and MySqlWhatever classes. // there ist enforce(cond, msg) for this in std.exception/std.conv, dunno. if (!exists(confpath)) throw new Exception("ERROR: config.ini do not exis

Re: How to create instance of class that get data from 2 another instance?

2015-01-02 Thread Tobias Pankrath via Digitalmars-d-learn
On Friday, 2 January 2015 at 15:33:06 UTC, Suliman wrote: Thanks! I will try! D is my first compilable language, I wrote only some scripts without OO before. So in my case your suggestion is best practice? Or there is any more simple way to pass config and data to MySQL class? I think it's

Re: How to create instance of class that get data from 2 another instance?

2015-01-02 Thread Suliman via Digitalmars-d-learn
Thanks! I will try! D is my first compilable language, I wrote only some scripts without OO before. So in my case your suggestion is best practice? Or there is any more simple way to pass config and data to MySQL class?

Re: How to create instance of class that get data from 2 another instance?

2015-01-02 Thread Tobias Pankrath via Digitalmars-d-learn
On Friday, 2 January 2015 at 14:50:54 UTC, Suliman wrote: Anything declared in main() is local to main and not a global. Ok! So I need create multiple instances of the parseconfig? Or please suggest me any solution, I really can't understand how to be in such situation... Have you ever used

Re: How to create instance of class that get data from 2 another instance?

2015-01-02 Thread Suliman via Digitalmars-d-learn
Anything declared in main() is local to main and not a global. Ok! So I need create multiple instances of the parseconfig? Or please suggest me any solution, I really can't understand how to be in such situation...

Re: How to create instance of class that get data from 2 another instance?

2015-01-02 Thread Tobias Pankrath via Digitalmars-d-learn
On Friday, 2 January 2015 at 11:21:08 UTC, Suliman wrote: I looked at my code and it's seems that I can create instance of MySQL in main. void main() { auto parseconfig = new parseConfig(); auto mysql = new MySQL(parseconfig, seismodownload); } In parseConfig I am creation instance of seismoDo

Re: getting current DateTime

2015-01-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 02, 2015 08:31:11 Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/2/15 6:21 AM, Jonathan M Davis via Digitalmars-d-learn wrote: > > > The main places that code is likely to use DateTime is if it needs to > > operate on dates and times separately from any connection to

Re: Can the order in associative array change when keys are not midified?

2015-01-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/1/15 7:32 AM, Idan Arye wrote: If I have an associative array and I only modify it's values, without changing the keys, can I assume that the order won't change? I would never make that assumption. An AA is free to rehash at any time, for whatever reason. What I would say is that you ca

Re: getting current DateTime

2015-01-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/2/15 6:21 AM, Jonathan M Davis via Digitalmars-d-learn wrote: The main places that code is likely to use DateTime is if it needs to operate on dates and times separately from any connection to the system's time or time zones and when you want to get the separate pieces of the date and time

Re: What exactly shared means?

2015-01-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 02, 2015 11:47:46 Daniel Kozak via Digitalmars-d-learn wrote: > I always think that shared should be use to make variable global > across threads (similar to __gshared) with some synchronize > protection. But this code doesn't work (app is stuck on _aaGetX > or _aaRehash ): > > s

Re: What exactly shared means?

2015-01-02 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 2 January 2015 at 11:47:47 UTC, Daniel Kozak wrote: I always think that shared should be use to make variable global across threads (similar to __gshared) with some synchronize protection. But this code doesn't work (app is stuck on _aaGetX or _aaRehash ): But when I add synchroni

What exactly shared means?

2015-01-02 Thread Daniel Kozak via Digitalmars-d-learn
I always think that shared should be use to make variable global across threads (similar to __gshared) with some synchronize protection. But this code doesn't work (app is stuck on _aaGetX or _aaRehash ): shared double[size_t] logsA; void main() { auto logs = new double[1_000_000];

Re: Can the order in associative array change when keys are not midified?

2015-01-02 Thread Tobias Pankrath via Digitalmars-d-learn
On Thursday, 1 January 2015 at 18:58:04 UTC, Andrej Mitrovic via Digitalmars-d-learn wrote: On 1/1/15, Tobias Pankrath via Digitalmars-d-learn wrote: You could implement an OrderedMap!(Key, Value) via RedBlackTree!(Tuple!(Key, Value), (a,b) => a[0] < b[0]). We could add this as an alias into

Re: How to create instance of class that get data from 2 another instance?

2015-01-02 Thread Suliman via Digitalmars-d-learn
I looked at my code and it's seems that I can create instance of MySQL in main. void main() { auto parseconfig = new parseConfig(); auto mysql = new MySQL(parseconfig, seismodownload); } In parseConfig I am creation instance of seismoDownload: class parseConfig { if (checkLinkCode(emsc_cs

Re: getting current DateTime

2015-01-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, December 31, 2014 19:07:13 bitwise via Digitalmars-d-learn wrote: > > Why do you need DateTime and not SysTime? > > > > I'm actually surprised it doesn't have that too... > > > > -Steve > > Initially I was looking for something that would be the > equivalent to DateTime in C#. This no

Re: Scoped external function declaration

2015-01-02 Thread ketmar via Digitalmars-d-learn
On Fri, 02 Jan 2015 10:40:22 + novice2 via Digitalmars-d-learn wrote: > Thanx Daniel, thanx Ketmar. > > I just thinked that this is some sort of bug. > May be DMD should not change mangled name of external function... > Bit i dont know. with `extern(C)` it didn't. what you probably not reali

Re: Scoped external function declaration

2015-01-02 Thread novice2 via Digitalmars-d-learn
Thanx Daniel, thanx Ketmar. I just thinked that this is some sort of bug. May be DMD should not change mangled name of external function... Bit i dont know.

Re: How to create instance of class that get data from 2 another instance?

2015-01-02 Thread Suliman via Digitalmars-d-learn
What I am doing wrong? http://www.everfall.com/paste/id.php?iwh4qdcqv6zi Well, there's no `parseconfig` there. Do you expect the `parseconfig` from line 30 or line 193 to be available in line 170? From line 30. In line 193 I am get in instance of class instance of parseconfig to be able t