Re: core.atomic: atomicFence, atomicLoad, atomicStore

2015-01-12 Thread John Colvin via Digitalmars-d-learn
On Monday, 12 January 2015 at 13:37:19 UTC, ref2401 wrote: Thanks for the links. I have shared class instance. There are two threads which can read/write fields of the class. As i understand i can declare class as synchronized or i can read/write using atomicLoad/atomicStore. What's the

Re: casting SysTime to ubyte[]

2015-01-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/12/15 8:59 AM, Laeeth Isharc wrote: import std.datetime; import std.stdio; import std.conv; void main(string[] arg) { auto a=Clock.currTime(); auto b=cast(ubyte[])a; writefln(%s,b); } how do i get the time as a binary representation I can write to a file? You can always

casting SysTime to ubyte[]

2015-01-12 Thread Laeeth Isharc via Digitalmars-d-learn
import std.datetime; import std.stdio; import std.conv; void main(string[] arg) { auto a=Clock.currTime(); auto b=cast(ubyte[])a; writefln(%s,b); } how do i get the time as a binary representation I can write to a file? Thanks.

Re: core.atomic: atomicFence, atomicLoad, atomicStore

2015-01-12 Thread ref2401 via Digitalmars-d-learn
Thanks for the links. I have shared class instance. There are two threads which can read/write fields of the class. As i understand i can declare class as synchronized or i can read/write using atomicLoad/atomicStore. What's the difference between these two approaches? In what circumstances

Re: casting SysTime to ubyte[]

2015-01-12 Thread Daniel Kozák via Digitalmars-d-learn
V Mon, 12 Jan 2015 13:59:27 + Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: import std.datetime; import std.stdio; import std.conv; void main(string[] arg) { auto a=Clock.currTime(); auto b=cast(ubyte[])a; writefln(%s,b); }

Re: endsWith - for a string vs an array of strings

2015-01-12 Thread Laeeth Isharc via Digitalmars-d-learn
Thanks for the help to everyone. It seems a common thing to want to check an array as one may not know the variables at compile time. Not that it's more than a few lines to do in D. But in terms of language adoption, small frictions can have large consequences over time. (Modern people

Re: Wrapping a C library with its own GC + classes vs refcounted structs

2015-01-12 Thread Laeeth Isharc via Digitalmars-d-learn
Laeeth. Thanks for the reply. Yes, this concerns my HDF5 wrapper project; the main concern is not that the memory consumption of course, but rather explicitly controlling lifetimes of the objects (especially objects like files -- so you are can be sure there are no zombie handles floating

Re: Set null as function array parameter

2015-01-12 Thread ketmar via Digitalmars-d-learn
On Mon, 12 Jan 2015 16:32:30 + Oleg via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 12 January 2015 at 15:59:43 UTC, Adam D. Ruppe wrote: Why are you using ref? Take that off and you can pass any array, including null, with ease. Because dynamic arrays are

Re: Set null as function array parameter

2015-01-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 12 January 2015 at 15:51:17 UTC, Oleg wrote: void foo(ref int[] param1) {} Why are you using ref? Take that off and you can pass any array, including null, with ease. The only difference is changes to length won't be seen outside the foo function.

Re: Set null as function array parameter

2015-01-12 Thread Oleg via Digitalmars-d-learn
On Monday, 12 January 2015 at 15:59:43 UTC, Adam D. Ruppe wrote: Why are you using ref? Take that off and you can pass any array, including null, with ease. Because dynamic arrays are passed by value to functions. Will it make another copy of array, if I'll pass array by value? Looks like

D Beginner Trying Manual Memory Management

2015-01-12 Thread jmh530 via Digitalmars-d-learn
I'm new to D. I have some modest knowledge of C++, but am more familiar with scripting languages (Matlab, Python, R). D seems so much easier than C++ in a lot of ways (and I just learned about rdmd today, which is pretty cool). I am concerned about performance of D vs. C++, so I wanted to

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread ketmar via Digitalmars-d-learn
On Mon, 12 Jan 2015 19:29:53 + jmh530 via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: the proper answer is too long to write (it will be more an article that a forum answer ;-), so i'll just give you some directions: import std.typecons; { auto b = scoped!B(); //

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread jmh530 via Digitalmars-d-learn
Thanks for the reply, I wasn't familiar with scoped. I was aware that structs are on the stack and classes are on the heap in D, but I didn't know it was possible to put a class on the stack. Might be interesting to see how this is implemented. After looking up some more C++, I think what I

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread ketmar via Digitalmars-d-learn
On Mon, 12 Jan 2015 20:14:19 + jmh530 via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Thanks for the reply, I wasn't familiar with scoped. I was aware that structs are on the stack and classes are on the heap in D, but I didn't know it was possible to put a class on the

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread aldanor via Digitalmars-d-learn
On Monday, 12 January 2015 at 20:30:45 UTC, ketmar via Digitalmars-d-learn wrote: it even has `RefCounted!`, but it doesn't play well with classes yet (AFAIR). I wonder if it's possible to somehow make a version of refcounted that would work with classes (even if limited/restricted in some

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread ketmar via Digitalmars-d-learn
On Mon, 12 Jan 2015 21:37:27 + aldanor via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 12 January 2015 at 20:30:45 UTC, ketmar via Digitalmars-d-learn wrote: it even has `RefCounted!`, but it doesn't play well with classes yet (AFAIR). I wonder if it's

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread aldanor via Digitalmars-d-learn
On Monday, 12 January 2015 at 21:54:51 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 12 Jan 2015 21:37:27 + aldanor via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 12 January 2015 at 20:30:45 UTC, ketmar via Digitalmars-d-learn wrote: it even has

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread Mike via Digitalmars-d-learn
On Monday, 12 January 2015 at 19:29:54 UTC, jmh530 wrote: I'm new to D. I have some modest knowledge of C++, but am more familiar with scripting languages (Matlab, Python, R). D seems so much easier than C++ in a lot of ways (and I just learned about rdmd today, which is pretty cool). I am

How to do equivalent of npm install --save with dub?

2015-01-12 Thread Andrew Grace via Digitalmars-d-learn
I am trying to play with D, but I'm getting stuck with the DUB package manager. If use DUB to download a package to my project, how do I get DUB to add what I downloaded to the dub.json file? I have tried DUB --fetch --cache=local http-parser (for example). It downloads the package, but

Re: Accessing class with module name as Java's

2015-01-12 Thread tcak via Digitalmars-d-learn
On Monday, 12 January 2015 at 18:11:35 UTC, bearophile wrote: D modules can contain lot of stuff, like variables, constants, enums, types, structs, etc. And you usually put more than one class in each D module. Also D class names should be capitalized (like Project). When I do this, it

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread jmh530 via Digitalmars-d-learn
I had seen some stuff on alias thing, but I hadn't bothered to try to understand it until now. If I'm understanding the first example a href=http://dlang.org/class.html#AliasThis;here/a, alias this let's you refer to x in s by writing either s.x (as normally) or just s. That didn't seem that

Re: How to do equivalent of npm install --save with dub?

2015-01-12 Thread Rikki Cattermole via Digitalmars-d-learn
On 13/01/2015 2:01 p.m., Andrew Grace wrote: I am trying to play with D, but I'm getting stuck with the DUB package manager. If use DUB to download a package to my project, how do I get DUB to add what I downloaded to the dub.json file? I have tried DUB --fetch --cache=local http-parser (for

Re: How to interface with C++ code or dll?

2015-01-12 Thread Suliman via Digitalmars-d-learn
Thanks for detail answer. I stopped at error: source\cpl_vsi.d(70): Error: module stat is in file 'std\c\stat.d' which cannot be read I do not know where I can find this module. If someone wan't to attempt to create binding, or finish my here is link of my half-done job

Re: Accessing class with module name as Java's

2015-01-12 Thread Ali Çehreli via Digitalmars-d-learn
On 01/12/2015 10:09 PM, tcak wrote: It is just making everything dirty. request.HttpSocketConnectionRequest connection.HttpSocketConnection You can name the files the same as their classes: HttpSocketConnectionRequest.d, etc. I just want to create a file called

Re: Accessing class with module name as Java's

2015-01-12 Thread tcak via Digitalmars-d-learn
What namespace? D has modules, unlike C++. In general it's a bad idea to have inside a module a name (like a variable name or struct name) equal to the module name, because it causes confusion. I am confused as well. core.stdc.errno @property int errno() { return getErrno(); } @property int

Re: Accessing class with module name as Java's

2015-01-12 Thread tcak via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 05:18:46 UTC, Ali Çehreli wrote: On 01/12/2015 08:22 PM, tcak wrote: What namespace? D has modules, unlike C++. In general it's a bad idea to have inside a module a name (like a variable name or struct name) equal to the module name, because it causes confusion.

Re: Accessing class with module name as Java's

2015-01-12 Thread Ali Çehreli via Digitalmars-d-learn
On 01/12/2015 08:22 PM, tcak wrote: What namespace? D has modules, unlike C++. In general it's a bad idea to have inside a module a name (like a variable name or struct name) equal to the module name, because it causes confusion. I am confused as well. core.stdc.errno @property int

Map Lambda with Side-Effects

2015-01-12 Thread Nordlöw
Somewhat related to https://github.com/D-Programming-Language/phobos/pull/2024 I wonder about the soundness of `map` in ```D import std.algorithm, std.range, std.stdio; void main(string[] args) { long[] arr; const n = 3; iota(n).map!(a = arr ~= a); writeln(arr);

Set null as function array parameter

2015-01-12 Thread Oleg via Digitalmars-d-learn
Hello. How can I call a function with null as parameter, which I don't want to set. For example: void foo(ref int[] param1) {} I can't call this function like: foo(null); Is it possible to set default value for an array parameter or pass null/empty array? I can create empty array and pass it,

Re: Accessing class with module name as Java's

2015-01-12 Thread bearophile via Digitalmars-d-learn
tcak: One way I achieved it, though I cannot put namespace on it. file: project.d == module project; class project{} D modules can contain lot of stuff, like variables, constants, enums, types, structs, etc. And you usually put more than one class in each D module. Also D

Re: Set null as function array parameter

2015-01-12 Thread Oleg via Digitalmars-d-learn
On Monday, 12 January 2015 at 16:44:42 UTC, ketmar via Digitalmars-d-learn wrote: nope, it means exactly what is written there. except that dynamic array is represented by struct like this: struct { void *dataptr; size_t itemCount; } this is what D calls dynamic array, and this is

Re: Set null as function array parameter

2015-01-12 Thread ketmar via Digitalmars-d-learn
On Mon, 12 Jan 2015 16:53:59 + Oleg via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 12 January 2015 at 16:44:42 UTC, ketmar via Digitalmars-d-learn wrote: nope, it means exactly what is written there. except that dynamic array is represented by struct

Re: casting SysTime to ubyte[]

2015-01-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 12, 2015 13:59:27 Laeeth Isharc via Digitalmars-d-learn wrote: import std.datetime; import std.stdio; import std.conv; void main(string[] arg) { auto a=Clock.currTime(); auto b=cast(ubyte[])a; writefln(%s,b); } how do i get the time as a binary representation

Accessing class with module name as Java's

2015-01-12 Thread tcak via Digitalmars-d-learn
In java, if I create a file, the class that is defined in it must have the same name of file. So, with the file name, I can relate to class directly. Is there any way to achieve this in D? One way I achieved it, though I cannot put namespace on it. file: project.d == module

Re: Set null as function array parameter

2015-01-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 12 January 2015 at 16:32:31 UTC, Oleg wrote: Because dynamic arrays are passed by value to functions. Will it make another copy of array, if I'll pass array by value? It is important to think of the underlying representation with a pointer and length passed by value. Since it is a