Re: Typed Message Passing between D Processes
On Wednesday, 29 July 2015 at 16:36:41 UTC, Atila Neves wrote: LDC: Cerealed: 970 ms, 482 μs, and 6 hnsecs MsgPack: 896 ms, 591 μs, and 2 hnsecs Not too shabby! Atila cool. what are the advantages of cereald over msgpack? can you stream in packets with cereald too? cool thing about msgpack is that there exist libraries for many language. so we use it do actually store logs and then process them with other tools too.
Re: How disruptive is the GC?
On Wednesday, 29 July 2015 at 17:09:52 UTC, Namespace wrote: On Wednesday, 29 July 2015 at 09:25:50 UTC, Snape wrote: I'm in the early stages of building a little game with OpenGL (in D) and I just want to know the facts about the GC before I decide to either use it or work around it. Lots of people have said lots of things about it, but some of that information is old, so as of today, what effect does the GC have on the smooth operation of a real-time application? Is it pretty noticeable with any use of the GC or only if you're deallocating large chunks at a time? http://3d.benjamin-thaut.de/?p=20 Note that this was 3 years ago, so there have been GC improvements since then. I'm not sure what the results would be like today (or what the code is like in terms of needless allocations). That being said, you probably want to avoid the GC as much as possible for games. Luckily we have tools like -vgc to help with that now (and @nogc, but I still consider this mostly unusable thanks largely to exceptions).
Compiling a DLL with DMC
I'm trying to compile a DLL using DMC for use in a sample DMD program, but the link stage keeps failing and I can't figure out why. The C source: ``` #include #ifdef __DMC__ #define WIN32_LEAN_AND_MEAN #include BOOL APIENTRY DllMain(HANDLE hModule, DWORD reason, LPVOID lpReserved) { switch (reason) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } #endif int some_c_function(int a) { printf("Hello, D! From C! %d", a); return a + 20; } ``` The definition file: EXPORTS DllMain some_c_function The command line: dmc -mn -WD dll-testing.cpp kernel32.lib clib.def The errors: OPTLINK : Error 180: No Match Found for Export/ENTRY - : DllMain OPTLINK : Error 180: No Match Found for Export/ENTRY - : some_c_function OPTLINK : Warning 148: USE16/USE32 Mismatch : DGROUP C:\dm\bin\..\lib\SNN.lib(dllstart) Error 83: Illegal frame on start address OPTLINK : Warning 174: 32-bit Segments Inappropriate for 16-bit Segmented output OPTLINK : Error 81: Cannot EXPORT : DllMain OPTLINK : Error 81: Cannot EXPORT : some_c_function clib.obj(clib) Error 35: Cannot Reach TARGET from FRAME at Relative 00024H from Segment _TEXT FRAME = Frame of Group FLAT TARGET = External Symbol _printf 001ACH FIXUPP Type = 32-bit Conditional JMP I've tried ditching the def file and using __declspec(dllexport) directly on the functions and got the same result. Does anyone know how to compile a DLL with DMC?
Re: Changes on dynamic shared library writing
On Thursday, 30 July 2015 at 03:52:16 UTC, Rikki Cattermole wrote: On 30/07/2015 8:27 a.m., tcak wrote: On Wednesday, 29 July 2015 at 19:41:14 UTC, tcak wrote: After a long time (Failed many times before), I checked the page http://dlang.org/dll-linux.html again. It shows a message on top saying that preliminary and subject to change. Exactly what changes are expected? Where can I learn about them? I would do tests again with dynamic library writing on Linux. Still same problem. I copied and pasted the latest codes from that web page. A D library, and a D executable is created. I copied the libphobos2.so from /usr/lib/x86_64-linux-gnu/libphobos2.so to current directory. Changed both of rpath values to "." to indicated local phobos library. Everything works correctly. Then I copied main, dll, and libphobos to UbuntuMATE on VirtualBox. It runs on Live CD. Then tried to execute main there. Result is as below: ./app.exe: error while loading shared libraries: libphobos2.so.0.67: cannot open shared object file: No such file or directory This was happening before and still same. I want to develop the app and library, and copy it to web server where DMD won't be installed. This is creating problem to me. Did you try renaming "libphobos2.so" to "libphobos2.so.0.67"? After all, that is what it is looking for. I copied libphobos to /usr/lib/x86_64.../ Then created a soft link with "ln -s" for libphobos2.so.0.67. But later I realised that link wasn't set correctly. Before that I wrote the message. So thankfully it works now. But I am still wondering what changes would be coming to there. There was a thread I was reading that is started by Andrei in 2012 about shared library issues. Someone asks whether they are resolved in 2013, another asks in 2014. Now we are in 2015. I am not sure if there is any resolutions about them.
Re: Changes on dynamic shared library writing
On 30/07/2015 8:27 a.m., tcak wrote: On Wednesday, 29 July 2015 at 19:41:14 UTC, tcak wrote: After a long time (Failed many times before), I checked the page http://dlang.org/dll-linux.html again. It shows a message on top saying that preliminary and subject to change. Exactly what changes are expected? Where can I learn about them? I would do tests again with dynamic library writing on Linux. Still same problem. I copied and pasted the latest codes from that web page. A D library, and a D executable is created. I copied the libphobos2.so from /usr/lib/x86_64-linux-gnu/libphobos2.so to current directory. Changed both of rpath values to "." to indicated local phobos library. Everything works correctly. Then I copied main, dll, and libphobos to UbuntuMATE on VirtualBox. It runs on Live CD. Then tried to execute main there. Result is as below: ./app.exe: error while loading shared libraries: libphobos2.so.0.67: cannot open shared object file: No such file or directory This was happening before and still same. I want to develop the app and library, and copy it to web server where DMD won't be installed. This is creating problem to me. Did you try renaming "libphobos2.so" to "libphobos2.so.0.67"? After all, that is what it is looking for.
Re: Type inference of a function parameter
On Wednesday, 29 July 2015 at 20:20:47 UTC, Adel Mamin wrote: Hello, Why dmd cannot inference the type of 'arr' in my_func() parameter? test.d: import std.stdio; void my_func(auto arr) { writeln(arr); } void main() { auto arr = new int[5]; arr = [1, 2, 3, 4, 5]; my_func(arr); } dmd test.d test.d(3): Error: undefined identifier arr Consider what would happen if my_func is compiled in a library. How would the compiler know what type arr is if there is no code around that is calling it? In that case, it would be unable to compile the function. Furthermore, what happens if my_func is called with multiple types? A function has one instance and one instance only, so arr can only ever be one type. With templates, the code is always available, so the compiler can always know what the type is inside the function. And you can have multiple instances of any template, so it's possible for arr to be different types.
Re: extern(C) with function returning user type
On Wednesday, 29 July 2015 at 18:42:45 UTC, Kyoji Klyden wrote: Thanks for the replies, This issue really highlights one of D's weak points I think. I've atleast got a round about solution almost working. :P Really? I see it as one of D's strengths. It's much easier to connect D with C than it is to connect other languages with C. Essentially, you're just rewriting the C header in D and that's it. It's as simple as it can get without the compiler being able to directly parse C headers. In that case, the compiler would either be needlessly complex or have a dependency on something like libclang. This is much more appropriate for a tool, not the compiler. Besides, it's quite easy to do it by hand.
Re: How to make a standalone .a using dub?
On Thursday, 30 July 2015 at 00:14:23 UTC, Yuxuan Shui wrote: Is there a way to have dub pack the library along with all its dependencies into a single .a? And if not, is there any D build system capable of doing this? reggae maybe?
How to make a standalone .a using dub?
Is there a way to have dub pack the library along with all its dependencies into a single .a?
Re: forward range properties with alias this - how?
On Wednesday, 29 July 2015 at 23:54:29 UTC, Ivan Kazmenko wrote: On Wednesday, 29 July 2015 at 12:25:14 UTC, Marc Schütz wrote: On Tuesday, 28 July 2015 at 21:25:23 UTC, Ivan Kazmenko wrote: ... Perhaps I still don't implement save() correctly. The line @property auto save() {return S(contents.dup);} was meant to be just: @property auto save() {return S(contents);} But with either of them, I get an error when trying a function using save. - import std.algorithm, std.range, std.stdio; struct S { int[] contents; alias contents this; @property auto save() {return S(contents);} auto opSlice(size_t lo, size_t hi) {return S(contents[lo..hi]);} } void main() { S s; s = [4, 3, 2, 1]; nextPermutation(s); } - The error is: - sorting.d(2460): Warning: use std.algorithm.reverse instead of .reverse property sorting.d(2460): Error: function expected before (), not _adReverse(range.contents, 4u) of type int[] - So, is something wrong with my save()? Anyway, I reckon nextPermutation itself is wrong and should use reverse(range); instead of range.reverse(); as it does ten lines later: https://github.com/D-Programming-Language/phobos/blob/30e4ff1717d6d3eb82d2cb0e00a3c07af4263a7b/std/algorithm/sorting.d#L2468-L2478 If anybody can confirm that, I can file an issue and a patch.
Re: forward range properties with alias this - how?
On Wednesday, 29 July 2015 at 12:25:14 UTC, Marc Schütz wrote: On Tuesday, 28 July 2015 at 21:25:23 UTC, Ivan Kazmenko wrote: Hello, I wrap an array into a struct. Then I use alias this to expose the array functionality. Sadly, range properties of the array are not forwarded, and so I can't use the struct as an array with functions from std.algorithm and std.range. - import std.range, std.stdio; struct S { int[] contents; alias contents this; } void main() { S s; writeln(hasSlicing!(S)); // false } - I would like to be able to do that, however. 1. Why exactly hasSlicing (et al.) does not check the alias this-ed array when it checks the struct? 2. What should I do? The solution I can think of is to insert the 3-6 range functions which forward the functionality to the underlying array, perhaps as a mixin. Ivan Kazmenko. `hasSlicing` explicitly checks whether the result of the slice operator has the same type as the original: https://github.com/D-Programming-Language/phobos/blob/master/std/range/primitives.d#L1499-L1500 If you remove the `static assert()` and change the next line to use `auto`, and do the same in the other two places in this templates, it will work. Thank you, the matter got clearer after reading the right piece of code and your explanation. By the way, the documentation around these source lines always repeats a slightly outdated version of the unittests. Shouldn't it be brought in sync, perhaps by using the modern DRY way: /// unittest {...} Or will that necessarily precede the unittest with "Example:"? At any rate, I doubt the ~20 lines of introspection code - which sometimes gets outdated - should appear at all in hasSlicing et al. documentation. If a developer encounters problems with hasSlicing and needs the source, a link to the up-to-date source itself may be enough. I don't know whether this is intentional. I'd say we should allow a sliceable range to have slices of a different type. EDIT: The documentation even says that it's intentional, but gives no justification. I don't know why the type should be the same, but that may well be needed. Anyway, after more digging, I found out I only need to implement save() to satisfy isRandomAccessRange, which makes sense when I think of it: the save() for arrays returns an array and not my struct. And opSlice(...) to satisfy hasSlicing, which also makes sense if we accept that the slice needs to be the same type: a generic opSlice is not possible since operator overloads must be member functions, and even if it were, it would not know how to construct an object of our specific type in the general case. So, that's some boilerplate, but its appearance seems justified. Here's the working code I got: - import std.algorithm, std.random, std.range, std.stdio; struct S { int[] contents; alias contents this; @property auto save() {return S(contents.dup);} auto opSlice(size_t lo, size_t hi) {return S(contents[lo..hi]);} } void main() { S s; s = [4, 3, 2, 1]; writeln(s[1..3]); // [3, 2] writeln(isInputRange!(S)); // true writeln(isForwardRange!(S)); // true writeln(isBidirectionalRange!(S)); // true writeln(isRandomAccessRange!(S)); // true writeln(hasSlicing!(S)); // true auto t = s; sort(s); writeln(s); // [1, 2, 3, 4] randomShuffle(s); writeln(s); // random permutation writeln(t); // same as above } - Now, if I remove the custom opSlice and alter the checks in hasSlicing as you suggested, I get the error: - sorting.d(1160): Error: quickSortImpl (S r, uint depth) is not callable using argument types (int[], uint) - Which means quickSortImpl (S r, uint depth) can't instantiate and call quickSortImpl (int[] r, uint depth) for recursively sorting its slices. That is understandable.
Re: Error: 'this' is only defined in non-static member functions, not main
On Wednesday, 29 July 2015 at 22:12:38 UTC, anonymous wrote: Slapping `static` on `get` seems to make it work: static size_t get() {return member.offsetof;} Good slap, thanks! you solved my problem I guess the compiler thinks that since `item.link` is an instance member, it needs a `this`. And then `get` would need a `this` too as it's using `item.link` via `member`. When the compiler sees that there is no `this`, it errors out. An explicit `static` forces the compiler to assume no `this`. And it would error out if you actually tried to make use of it. Naively, I'd think the compiler should be able to figure that out itself. I guess that is a dmd bug. I'll fill a report in case of.
Re: Compare types with `static if` in template function.
On 07/29/2015 11:54 AM, vladde wrote: On Wednesday, 29 July 2015 at 18:14:11 UTC, Ali Çehreli wrote: else if(is(typeof(c) == fg)) { // slots[xy.y][xy.x].fg = C; } The error occurs when the commented line is run. The full code can be viewed at https://github.com/vladdeSV/clayers/blob/change-slot/source/clayers.d You seem to be using type names instead of member names: static if(is(typeof(c) == dchar) || is(typeof(c) == char)) { slots[xy.y][xy.x].character = c; } else if(is(typeof(c) == fg)) { slots[xy.y][xy.x].fg = c; Should be ... color = c; } else if(is(typeof(c) == bg)) { slots[xy.y][xy.x].bg = c; ... background = c; } else if(is(typeof(c) == md)) { slots[xy.y][xy.x].md = c; ... mode = c; } Ali
Re: Error: 'this' is only defined in non-static member functions, not main
On Wednesday, 29 July 2015 at 21:33:16 UTC, remi thebault wrote: Hello I have this weird error trying to achieve something simple: That's far from simple. Here's a reduction: template wl_container_of(alias member) { size_t get() {return member.offsetof;} } struct item { int link; } void main() { wl_container_of!(item.link).get(); /* Error: 'this' is only defined in non-static member functions, not main */ } I'm not sure what's going on here, if this should or shouldn't work. The error message isn't exactly good. Slapping `static` on `get` seems to make it work: static size_t get() {return member.offsetof;} I guess the compiler thinks that since `item.link` is an instance member, it needs a `this`. And then `get` would need a `this` too as it's using `item.link` via `member`. When the compiler sees that there is no `this`, it errors out. An explicit `static` forces the compiler to assume no `this`. And it would error out if you actually tried to make use of it. Naively, I'd think the compiler should be able to figure that out itself.
Error: 'this' is only defined in non-static member functions, not main
Hello I have this weird error trying to achieve something simple: module list_test; // import wayland.util; template Id(alias a) { alias Id = a; } template ParentOf(alias member) { alias ParentOf = Id!(__traits(parent, member)); } template wl_container_of(alias member) { ParentOf!(member)* get(wl_list* ptr) { return cast(ParentOf!(member)*)(cast(ptrdiff_t)(ptr)-member.offsetof); } } struct wl_list { wl_list *prev; wl_list *next; } struct item { int num; wl_list link; this(int num) { this.num = num; } } int main (string[] args) { auto i1 = item(1); auto i2 = item(2); auto i3 = item(3); wl_list lst; // wl_list_init(&lst); // wl_list_insert(&lst, &i1.link); // wl_list_insert(&lst, &i2.link); // wl_list_insert(&i2.link, &i3.link); item *it = wl_container_of!(item.link).get(&i2.link); // error on this line return 0; } If I change the definition of wl_container_of to: template wl_container_of(alias member) { ParentOf!(member)* wl_container_of(wl_list* ptr) { return cast(ParentOf!(member)*)(cast(ptrdiff_t)(ptr)-member.offsetof); } } and call to: wl_container_of!(item.link)(&i2.link); I now get a different error: Error: need 'this' for 'wl_container_of' of type 'pure nothrow @nogc @system item*(wl_list* ptr)' I run dmd v2.067 on linux 64bits. Any idea? thanks Rémi
Re: Type inference of a function parameter
On Wednesday, 29 July 2015 at 20:20:47 UTC, Adel Mamin wrote: void my_func(auto arr) { writeln(arr); } There are no `auto` parameters in D. You have to make it a template explicitly: void my_func(A)(A arr) { writeln(arr); }
Re: Changes on dynamic shared library writing
On Wednesday, 29 July 2015 at 19:41:14 UTC, tcak wrote: After a long time (Failed many times before), I checked the page http://dlang.org/dll-linux.html again. It shows a message on top saying that preliminary and subject to change. Exactly what changes are expected? Where can I learn about them? I would do tests again with dynamic library writing on Linux. Still same problem. I copied and pasted the latest codes from that web page. A D library, and a D executable is created. I copied the libphobos2.so from /usr/lib/x86_64-linux-gnu/libphobos2.so to current directory. Changed both of rpath values to "." to indicated local phobos library. Everything works correctly. Then I copied main, dll, and libphobos to UbuntuMATE on VirtualBox. It runs on Live CD. Then tried to execute main there. Result is as below: ./app.exe: error while loading shared libraries: libphobos2.so.0.67: cannot open shared object file: No such file or directory This was happening before and still same. I want to develop the app and library, and copy it to web server where DMD won't be installed. This is creating problem to me.
Type inference of a function parameter
Hello, Why dmd cannot inference the type of 'arr' in my_func() parameter? test.d: import std.stdio; void my_func(auto arr) { writeln(arr); } void main() { auto arr = new int[5]; arr = [1, 2, 3, 4, 5]; my_func(arr); } dmd test.d test.d(3): Error: undefined identifier arr Adel
Changes on dynamic shared library writing
After a long time (Failed many times before), I checked the page http://dlang.org/dll-linux.html again. It shows a message on top saying that preliminary and subject to change. Exactly what changes are expected? Where can I learn about them? I would do tests again with dynamic library writing on Linux.
Re: Struct that destroys its original handle on copy-by-value
On Wednesday, 29 July 2015 at 19:10:36 UTC, Adam D. Ruppe wrote: On Sunday, 26 July 2015 at 12:16:30 UTC, Joseph Rushton Wakeling wrote: My aim by contrast is to _allow_ that kind of use, but render the original handle empty when it's done. I don't think D offers any way to do that. With the disabled postblit, you can force people into a method you write that returns a new copy and clears the original, but that won't just work with assignment. The ref assign might not be forbidden by the written doc but I'm guessing that is just an oversight - struct assignment in D never clears the original, it is always a simple copy (perhaps plus other code) Slightly OT, but this is something that would be possible with a copy constructor, I think?
Re: Struct that destroys its original handle on copy-by-value
On Sunday, 26 July 2015 at 12:16:30 UTC, Joseph Rushton Wakeling wrote: My aim by contrast is to _allow_ that kind of use, but render the original handle empty when it's done. I don't think D offers any way to do that. With the disabled postblit, you can force people into a method you write that returns a new copy and clears the original, but that won't just work with assignment. The ref assign might not be forbidden by the written doc but I'm guessing that is just an oversight - struct assignment in D never clears the original, it is always a simple copy (perhaps plus other code)
Re: Compare types with `static if` in template function.
On Wednesday, 29 July 2015 at 18:14:11 UTC, Ali Çehreli wrote: else if(is(typeof(c) == fg)) { // slots[xy.y][xy.x].fg = C; } The error occurs when the commented line is run. The full code can be viewed at https://github.com/vladdeSV/clayers/blob/change-slot/source/clayers.d
Re: Struct that destroys its original handle on copy-by-value
On Sunday, 26 July 2015 at 11:30:16 UTC, Joseph Rushton Wakeling wrote: Hello all, A design question that came up during the hackathon held during the last Berlin D Meetup. [...] Ping on the above -- nobody has any insight...?
Re: extern(C) with function returning user type
Thanks for the replies, This issue really highlights one of D's weak points I think. I've atleast got a round about solution almost working. :P
Re: No Unix socket support?
On Wednesday, 29 July 2015 at 13:39:33 UTC, simendsjo wrote: Is there no Unix socket support in Phobos? Or vibe? Or any other library? I've found some discussions: * https://issues.dlang.org/show_bug.cgi?id=9384 * http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/10870/ , but it seems there are no support yet. I defined a module with "class UnixAddress: Address{}" and "class UnixSocket: Socket{}" and made a small implementation 2 years ago. It still works perfectly. If interested, I can post it here. It is 69 lines only.
Re: extern(C) with function returning user type
On Wednesday, 29 July 2015 at 17:59:26 UTC, Kyoji Klyden wrote: How would I use a C function that's returning a struct? auto doesn't work here, and from what I can tell D can't import C headers. (If it really can't then, that would be a very welcome feature) I do have the required libs but I can't create my D obj file so I can't really get there. I know that there htod but, is there anyway I can avoid using that? I'm using GDC, and GCC on Win7 D can't import C header files. And I don't think such a feature is planned right now. You have to translate the C declarations to D, both struct and function. You can do that either manually or using some tool. If you go the manual route, there's a page on that: http://dlang.org/ctod.html For tools, if you're not happy with htod, maybe DStep works better: https://github.com/jacob-carlborg/dstep
Re: extern(C) with function returning user type
On 07/29/2015 10:59 AM, Kyoji Klyden wrote: > How would I use a C function that's returning a struct? The binding file must have a matching D struct. > auto doesn't > work here, and from what I can tell D can't import C headers. (If it > really can't then, that would be a very welcome feature) Header files require a C preprocessor but D does not have one and it does not want one. :) Check Deimos for examples and whether there are bindings already available for your lib: https://github.com/D-Programming-Deimos/ Ali
Re: extern(C) with function returning user type
On Wednesday, 29 July 2015 at 17:59:26 UTC, Kyoji Klyden wrote: How would I use a C function that's returning a struct? auto doesn't work here, and from what I can tell D can't import C headers. (If it really can't then, that would be a very welcome feature) I do have the required libs but I can't create my D obj file so I can't really get there. I know that there htod but, is there anyway I can avoid using that? I'm using GDC, and GCC on Win7 checkout dstep https://github.com/jacob-carlborg/dstep i think you can just define a struct with the same shape. see also mike's answer on http://forum.dlang.org/post/yheamworbhcaprrko...@forum.dlang.org
Re: Compare types with `static if` in template function.
On 07/29/2015 11:08 AM, vladde wrote: On Wednesday, 29 July 2015 at 18:04:48 UTC, vladde wrote: Apparently, if I only check for a character the code compiles without the need of static if. if(is(typeof(c) == dchar) || is(typeof(c) == char)){ slots[xy.y][xy.x].character = c; } //Compiles and works as expected And changing all if statements to static if still does not compile. The error may be the capital C in the else branch. (?) Can you provide complete code please? The following compiles with dmd 2.067: struct XY {size_t x, y;} private template color_type(int offset) { static enum type : int { init = 39 + offset, black = 30 + offset, red = 31 + offset, green = 32 + offset, yellow = 33 + offset, blue= 34 + offset, magenta = 35 + offset, cyan= 36 + offset, white = 37 + offset, light_black = 90 + offset, light_red = 91 + offset, light_green = 92 + offset, light_yellow = 93 + offset, light_blue= 94 + offset, light_magenta = 95 + offset, light_cyan= 96 + offset, light_white = 97 + offset } } alias color_type!0 .type fg; // alias fg = colorize.fg; //[2] void changeSlot(C...)(XY xy, C changes){ foreach(c; changes){ static if(is(typeof(c) == dchar) || is(typeof(c) == char)) { // slots[xy.y][xy.x].character = c; } else if(is(typeof(c) == fg)) { // slots[xy.y][xy.x].fg = C; } } } void main() { changeSlot(XY(10, 15), fg.red); } Ali
Re: Compare types with `static if` in template function.
On Wednesday, 29 July 2015 at 18:04:48 UTC, vladde wrote: Apparently, if I only check for a character the code compiles without the need of static if. if(is(typeof(c) == dchar) || is(typeof(c) == char)){ slots[xy.y][xy.x].character = c; } //Compiles and works as expected And changing all if statements to static if still does not compile.
Re: Compare types with `static if` in template function.
On Wednesday, 29 July 2015 at 17:52:45 UTC, Ali Çehreli wrote: On 07/29/2015 10:48 AM, vladde wrote: > static if(is(typeof(c) == dchar) || is(typeof(c) == char)) > { > slots[xy.y][xy.x].character = c; > } > else if(is(typeof(c) == fg)) I don't know whether it is the reason here but you fell for one of the D traps. :( Most definitely, you want an 'else static if' there. Otherwise, for the fg case, what ends up in your code to be compiled is this: if(is(typeof(c) == fg)) Ali Apparently, if I only check for a character the code compiles without the need of static if. if(is(typeof(c) == dchar) || is(typeof(c) == char)){ slots[xy.y][xy.x].character = c; } //Compiles and works as expected
extern(C) with function returning user type
How would I use a C function that's returning a struct? auto doesn't work here, and from what I can tell D can't import C headers. (If it really can't then, that would be a very welcome feature) I do have the required libs but I can't create my D obj file so I can't really get there. I know that there htod but, is there anyway I can avoid using that? I'm using GDC, and GCC on Win7
Re: Compare types with `static if` in template function.
On 07/29/2015 10:48 AM, vladde wrote: > static if(is(typeof(c) == dchar) || is(typeof(c) == char)) > { > slots[xy.y][xy.x].character = c; > } > else if(is(typeof(c) == fg)) I don't know whether it is the reason here but you fell for one of the D traps. :( Most definitely, you want an 'else static if' there. Otherwise, for the fg case, what ends up in your code to be compiled is this: if(is(typeof(c) == fg)) Ali
Compare types with `static if` in template function.
I want to have a template function where I can throw in some stuff in the parameters, then run foreach+static ifs and check what type the current is. From my project clayers[1], I've taken out some parts. (Note the current code does not compile.) This is what I have so far: struct XY {size_t x, y;} alias fg = colorize.fg; //[2] [...] void changeSlot(C...)(XY xy, C changes){ foreach(c; changes){ static if(is(typeof(c) == dchar) || is(typeof(c) == char)) { slots[xy.y][xy.x].character = c; } else if(is(typeof(c) == fg)) { slots[xy.y][xy.x].fg = C; } } } [...] changeSlot(XY(10, 15), fg.red); For this demonstation I've chosen to only check for `char` and `fg`, but it's intended to check for multiple different types. (See [1]) Now when I try to compile, I get "Error: more than one argument for construction of int" for checking against fg. HOWEVER, the code functions properly when checking the type for characters. From what I understand, my thinking works, but checking with `fg` is causing some crux-flux. `fg` is created from a template, please take a look at [2]. What am I doing wrong when I check for the type of `fg`? TL;DR: Is there a way to check the type of `fg` with an static if? [1] = https://github.com/vladdeSV/clayers/blob/change-slot/source/clayers.d#L323 [2] = https://github.com/yamadapc/d-colorize/blob/master/source/colorize/colors.d#L37
Re: Dynamic memory
On Wednesday, 29 July 2015 at 08:03:06 UTC, anonymous wrote: int[2][] is exactly an dynamic array of (arrays with the length 2), the logic behind this notation is: 1. Array of 2 int -> int[2] 2. a dynamic array of 1. -> int[2][] (like SomeType[] is an array of SomeType) Thank you!
Re: How disruptive is the GC?
On Wednesday, 29 July 2015 at 09:25:50 UTC, Snape wrote: I'm in the early stages of building a little game with OpenGL (in D) and I just want to know the facts about the GC before I decide to either use it or work around it. Lots of people have said lots of things about it, but some of that information is old, so as of today, what effect does the GC have on the smooth operation of a real-time application? Is it pretty noticeable with any use of the GC or only if you're deallocating large chunks at a time? http://3d.benjamin-thaut.de/?p=20
Re: Typed Message Passing between D Processes
On Monday, 29 June 2015 at 13:59:37 UTC, Nordlöw wrote: On Monday, 29 June 2015 at 10:22:10 UTC, Atila Neves wrote: I guess I'm going to have benchmark this now... :) What about doing a memory profiling using DMD fresh builtin profiler of http://dpaste.dzfl.pl/17b0ed9c0204 ? I'm guessing the GC might give misguiding results as your testStruct returns a relatively small data structure. I would rather like to see a larger (randomized) structure being tested on. You could make use of my https://github.com/nordlow/justd/blob/master/random_ex.d for random instance generation :) I tried your code and added it to the benchmark. It didn't make much of a difference. Atila
Re: Typed Message Passing between D Processes
On Monday, 29 June 2015 at 10:22:10 UTC, Atila Neves wrote: On Monday, 29 June 2015 at 08:45:15 UTC, Atila Neves wrote: On Sunday, 28 June 2015 at 17:02:42 UTC, Nordlöw wrote: On Friday, 26 June 2015 at 21:40:49 UTC, Atila Neves wrote: I'd have to benchmark it against something, but I'm pretty sure cerealed is fast. Faster than msgpack? I guess I'm going to have benchmark this now... :) Atila In release builds, _nearly_. Here's the benchmark program: http://dpaste.dzfl.pl/17b0ed9c0204. Results below. msgpack is... fast. From the docs, cerealed seems to have more features that I actually use and need though. Results: DMD debug: Cerealed: 4 secs, 987 ms, 700 μs, and 5 hnsecs MsgPack: 1 sec, 771 ms, 713 μs, and 7 hnsecs DMD release: Cerealed: 2 secs, 556 ms, 714 μs, and 6 hnsecs MsgPack: 1 sec, 89 ms, 561 μs, and 3 hnsecs GDC debug: Cerealed: 4 secs, 863 ms, 501 μs, and 1 hnsec MsgPack: 2 secs, 32 ms, 53 μs, and 1 hnsec GDC release: Cerealed: 1 sec, 740 ms, 726 μs, and 4 hnsecs MsgPack: 1 sec, 20 ms, 287 μs, and 3 hnsecs LDC debug: Cerealed: 7 secs, 711 ms, 154 μs, and 4 hnsecs MsgPack: 3 secs, 694 ms, 566 μs, and 2 hnsecs LDC release: Cerealed: 1 sec, 795 ms, 380 μs, and 7 hnsecs MsgPack: 931 ms, 355 μs, and 5 hnsecs Before I had time to look into it, somebody graciously optimised cerealed for me in this PR: https://github.com/atilaneves/cerealed/pull/6 And now then benchmarks are (dub build --build=release, fastest of 10 runs for each compiler): DMD: Cerealed: 1 sec, 199 ms, 118 μs, and 1 hnsec MsgPack: 1 sec, 85 ms, and 516 μs GDC: Cerealed: 927 ms, 677 μs, and 4 hnsecs MsgPack: 1 sec, 32 ms, 736 μs, and 5 hnsecs LDC: Cerealed: 970 ms, 482 μs, and 6 hnsecs MsgPack: 896 ms, 591 μs, and 2 hnsecs Not too shabby! Atila
Re: Yes or No Options
On Monday, 27 July 2015 at 15:50:11 UTC, Alex wrote: Hey guys! I am super new to programming and still trying to learn the very basics via a book that I bought. Out of interest: what made you start with D? It's not the most obvious choice for a programming novice.
Re: No Unix socket support?
On Wednesday, 29 July 2015 at 13:39:33 UTC, simendsjo wrote: Is there no Unix socket support in Phobos? Or vibe? Or any other library? I've found some discussions: * https://issues.dlang.org/show_bug.cgi?id=9384 * http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/10870/ , but it seems there are no support yet. With the exception of the abstract type [1] it should work just fine. [1] http://man7.org/linux/man-pages/man7/unix.7.html
Re: No Unix socket support?
On Wed, Jul 29, 2015 at 01:39:31PM +, simendsjo via Digitalmars-d-learn wrote: > Is there no Unix socket support in Phobos? No, there's plenty of support. Just use a unix address when making a socket. I used it in my terminal emulator: https://github.com/adamdruppe/terminal-emulator/blob/master/attach.d#L523
No Unix socket support?
Is there no Unix socket support in Phobos? Or vibe? Or any other library? I've found some discussions: * https://issues.dlang.org/show_bug.cgi?id=9384 * http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/10870/ , but it seems there are no support yet.
Re: forward range properties with alias this - how?
On Tuesday, 28 July 2015 at 21:25:23 UTC, Ivan Kazmenko wrote: Hello, I wrap an array into a struct. Then I use alias this to expose the array functionality. Sadly, range properties of the array are not forwarded, and so I can't use the struct as an array with functions from std.algorithm and std.range. - import std.range, std.stdio; struct S { int[] contents; alias contents this; } void main() { S s; writeln(hasSlicing!(S)); // false } - I would like to be able to do that, however. 1. Why exactly hasSlicing (et al.) does not check the alias this-ed array when it checks the struct? 2. What should I do? The solution I can think of is to insert the 3-6 range functions which forward the functionality to the underlying array, perhaps as a mixin. Ivan Kazmenko. `hasSlicing` explicitly checks whether the result of the slice operator has the same type as the original: https://github.com/D-Programming-Language/phobos/blob/master/std/range/primitives.d#L1499-L1500 If you remove the `static assert()` and change the next line to use `auto`, and do the same in the other two places in this templates, it will work. I don't know whether this is intentional. I'd say we should allow a sliceable range to have slices of a different type. EDIT: The documentation even says that it's intentional, but gives no justification.
Re: How disruptive is the GC?
On 29/07/2015 9:25 p.m., Snape wrote: I'm in the early stages of building a little game with OpenGL (in D) and I just want to know the facts about the GC before I decide to either use it or work around it. Lots of people have said lots of things about it, but some of that information is old, so as of today, what effect does the GC have on the smooth operation of a real-time application? Is it pretty noticeable with any use of the GC or only if you're deallocating large chunks at a time? Some tips: - Avoid allocations if possible - Use buffers/preallocated memory if possible - Disable the GC (collection only) - Use allocators instead of e.g. new - -vgc is awesome If you are using GC to allocate (not really a good idea), run collect when you have some spare cycles. Can't really say much about the current GC implementation. But what I do know is for real time apps GC is not a good tool for memory management.
How disruptive is the GC?
I'm in the early stages of building a little game with OpenGL (in D) and I just want to know the facts about the GC before I decide to either use it or work around it. Lots of people have said lots of things about it, but some of that information is old, so as of today, what effect does the GC have on the smooth operation of a real-time application? Is it pretty noticeable with any use of the GC or only if you're deallocating large chunks at a time?
Re: Dynamic memory
On Tuesday, 28 July 2015 at 22:52:31 UTC, Binarydepth wrote: I'm reading the reference : http://dlang.org/arrays.html And I'm declaring two dynamic arrays as I understand. What I had in mind was declaring a dynamic array of two elements each. int[2][] is exactly an dynamic array of (arrays with the length 2), the logic behind this notation is: 1. Array of 2 int -> int[2] 2. a dynamic array of 1. -> int[2][] (like SomeType[] is an array of SomeType) If you define SomeType e.g. as struct SomeType { int firstElement; int secondElement; } you get something similar. Yes, this is different from e.g. Java, where new int[2][42] creates an array of 2 arrays with 42 elements each. Accessing int[2][] nums : 1. nums[5] is the 5th element of nums which is of type int[2] 2. nums[5][0] is the zeroth element of 5th element of nums int[2] tmp = nums[5]; int value = tmp[0]; does the same...