Re: Creating D bindings for a C library
On Tuesday, 24 November 2015 at 23:22:24 UTC, Joseph Rushton Wakeling wrote: On Tuesday, 24 November 2015 at 23:14:14 UTC, Joseph Rushton Wakeling wrote: I'm considering creating some D bindings for a C library. I should probably clarify that I know what to do assuming I have to write all the bindings manually. However, as the library has quite a lot of header files, I'd really much rather auto-convert as much as possible, hence the questions above :-) If doing it by hand, some tips here: http://p0nce.github.io/d-idioms/#Porting-from-C-gotchas
Re: How to use readText to read utf16 file?
On Tuesday, 17 November 2015 at 05:37:55 UTC, Domain wrote: Thank you! Now another question: how to handle endianness? If your file follow a file format: the endianness should be defined there. else it's a random text file: either it will have a BOM with endianness, or you will have to guess.
Re: OSX Foundation framework D binding
On Wednesday, 11 November 2015 at 16:06:57 UTC, Jacob Carlborg wrote: On 2015-11-11 10:29, Daniel Kozak via Digitalmars-d-learn wrote: I find only this one: http://code.dlang.org/packages/derelict-cocoa Also, there's no point in complicate the bindings by using function pointers like this. Opinion. I only ever got problems with bindings that aren't dynamic. For example that problem would not happen with dynamic loading. https://github.com/nomad-software/x11/issues/11
Re: Feature for paranoids
On Tuesday, 10 November 2015 at 13:09:09 UTC, Fyodor Ustinov wrote: Hi! Is it possible when using the "-release" indicate that this one in/out/invariant/assert should not to be disabled? WBR, Fyodor. Since assert(false) is special (cf. http://p0nce.github.io/d-idioms/#assert%28false%29-is-special) you can use the following construct to have always-on assertions: if (!cond) assert(false); instead of: assert(cond); But -release will still remove your in/out/invariant blocks.
Re: Feature for paranoids
On Tuesday, 10 November 2015 at 20:37:00 UTC, Fyodor Ustinov wrote: assert(false) AKA assert(0) - is a part of this language that I think it is absolute evil. WBR, Fyodor. I would say it's a minor evil, that create problems by needing an explanation. At this point it has been discussed to death already.
Re: Why my app require MSVCR120.dll?
On Friday, 6 November 2015 at 13:16:46 UTC, Suliman wrote: I wrote Application in D. That use next components: "colorize": ">=1.0.5", "ddbc": ">=0.2.11", "vibe-d": "~>0.7.26" On Windows 7 it's work fine. On Windows 10 (clean install) it's do not start and require MSVCR120.dll And I can't understand what component is pulling this lib as dependence. What would be if I am try to port my App to Linux? What compiler are you using?
Re: Playing audio files and related functions?
On Monday, 26 October 2015 at 21:25:58 UTC, Cleverson wrote: Hello, Is there any library or module for easily managing basic audio functions, e.g., play/pause/stop a sound? I can't find it amongst the standard library and the packages colection, or maybe I don't know how to search properly, since I'm new to D and its ecosystem. Thank you, Cleverson There doesn't seem to be a pure D solution but bindings to existing C or C++ libraries do exist. - SDL_mixer through DerelictSDL2: http://code.dlang.org/packages/derelict-sdl2 (is an extension of SDL). - FMOD through DerelictFMOD: http://code.dlang.org/packages/derelict-fmod (not free for commercial use) - BASS through DerelictBASS: http://code.dlang.org/packages/derelict_extras-bass (not free for commercial use)
Re: inout, delegates, and visitor functions.
On Saturday, 24 October 2015 at 11:28:17 UTC, Sebastien Alaiwan wrote: Hi ponce, Thanks for your suggestion. I think I may have found the beginning of a solution: class E { import std.traits; void apply(this F, U)(void delegate(U e) f) if(is(Unqual!U == E)) { f(this); } int val; } int main() { void setToZero(E e) { e.val = 0; } void printValue(const E e) { import std.stdio; writefln("Value: %s", e.val); } E obj; obj.apply(); obj.apply(); const(E) objConst; //objConst.apply(); objConst.apply(); return 0; } Clever. It works because of const inference on template functions. Didn't know you could use 'this' as a type.
Re: inout, delegates, and visitor functions.
On Saturday, 24 October 2015 at 08:51:58 UTC, Sebastien Alaiwan wrote: Hi all, I'm trying to get the following code to work. (This code is a simplified version of some algebraic type). Is it possible to only declare one version of the 'apply' function? Or should I declare the const version and the non-const version? I tried using "inout", but I got the following error: test.d(28): Error: inout method test.E.apply is not callable using a mutable object class E { void apply(void delegate(inout(E) e) f) inout { f(this); } int val; } void m() { void setToZero(E e) { e.val = 0; } void printValue(const E e) { import std.stdio; writefln("Value: %s", e.val); } E obj; obj.apply(); obj.apply(); } Thanks! Hi Sebastien, That was an interesting question and I didn't succeed with 'inout' either without duplicating apply. I have a partial solution here: http://dpaste.dzfl.pl/b5ec7f16b912 which templatizes the delegate type, but is probably not what you want. The qualifier is not carried on to the apply() function. When taking a const delegate it will still not be const.
Re: Interval Arithmetic
On Thursday, 1 October 2015 at 21:13:30 UTC, Marco Leise wrote: Nice to have in Phobos. I assume you have to set the correct control word depending on whether you perform math on the FPU or via SSE (as is standard for x86_64)? And I assume further that DMD always uses FPU math and other compilers provide flags to switch between FPU and SSE? I don't know which compiler use which. On x86_64, a compiler is in practice free to mix-and-match FPU and SSE, the instructions are still there and working.
Re: Interval Arithmetic
On Thursday, 1 October 2015 at 11:40:28 UTC, Marco Leise wrote: Note that the FP control word is per thread and any external code you call or even buggy interrupt handlers could change or reset it to defaults. Known cases include a faulty printer driver and Delphi's runtime, which enables FP exceptions to throw exceptions on division by 0. Just saying this so if it ever happens you have it in the back of your mind. Against interrupt handlers you probably cannot protect, but when calling other people's code it would be best not depend on what the FP control word is set to on return. `FloatingPointControl` is nice here, because you can temporarily set the rounding mode directly for a block of FP instructions where no external libraries are involved. I have a RAII struct to save/restore the FP control word. It also handle the SSE control word which unfortunately exist. https://github.com/p0nce/dplug/blob/master/plugin/dplug/plugin/fpcontrol.d
Re: Do users need to install VS runtime redistributable if linking with Microsoft linker?
On Monday, 28 September 2015 at 16:01:54 UTC, Sebastiaan Koppe wrote: I could not find out which redistributable I had to install (what version of VS did you have installed / on what version of windows are you?). I decided to install them all, but couldn't install the one for 2015 (due to Windows6.1-KB2999226-x64.msu). After trying some workarounds I gave up. You need the VC++ 2015 64-bit redistributable.
Re: Do users need to install VS runtime redistributable if linking with Microsoft linker?
On Tuesday, 29 September 2015 at 09:44:58 UTC, Sebastiaan Koppe wrote: On Tuesday, 29 September 2015 at 09:15:29 UTC, ponce wrote: On Monday, 28 September 2015 at 16:01:54 UTC, Sebastiaan Koppe wrote: I could not find out which redistributable I had to install (what version of VS did you have installed / on what version of windows are you?). I decided to install them all, but couldn't install the one for 2015 (due to Windows6.1-KB2999226-x64.msu). After trying some workarounds I gave up. You need the VC++ 2015 64-bit redistributable. Can you either link statically or try an older version of VC, one that is more likely to be found in the wild? (or does ldc require 2015?) No, not without rebuilding Phobos/druntime as it stands. https://github.com/ldc-developers/ldc/issues/1133 I really want to try your game :) Version 1.7 is still available and is compiled with DMD for 32-bit Windows. You can also clone the repo and type "dub": https://github.com/p0nce/Vibrant Given the general speed up with LDC, it would need more profiling/optimizing to get back to DMD. Maybe next release.
Re: Do users need to install VS runtime redistributable if linking with Microsoft linker?
On Monday, 28 September 2015 at 15:10:25 UTC, ponce wrote: Does it also affect executable made with DMD and linked with MS linker? Just tested: no.
Re: Do users need to install VS runtime redistributable if linking with Microsoft linker?
On Monday, 28 September 2015 at 16:01:54 UTC, Sebastiaan Koppe wrote: On Monday, 28 September 2015 at 15:10:25 UTC, ponce wrote: On Tuesday, 22 September 2015 at 09:38:12 UTC, thedeemon wrote: On Monday, 21 September 2015 at 15:00:24 UTC, ponce wrote: All in the title. DMD 64-bit links with the VS linker. Do users need to install the VS redistributable libraries? I think they don't. Generated .exe seems to depend only on kernel32.dll and shell32.dll, i.e. things users already have. So I've released software with LDC 0.16.0-alpha4 Win64, and one user send me that http://i.imgur.com/xbU1VeS.png I thought it was only used for linking :( Does it also affect executable made with DMD and linked with MS linker? Basically you executable is bound to whatever runtime you had installed when linking the thing. If those aren't installed on the end user's machine, you get that error. Pretty neat huh? OK, but why does that need to happen? I don't get why does linking with MS linker implies a runtime dependency. I thought we would be left out of these sort of problems when using D :(
Re: Do users need to install VS runtime redistributable if linking with Microsoft linker?
On Tuesday, 22 September 2015 at 09:38:12 UTC, thedeemon wrote: On Monday, 21 September 2015 at 15:00:24 UTC, ponce wrote: All in the title. DMD 64-bit links with the VS linker. Do users need to install the VS redistributable libraries? I think they don't. Generated .exe seems to depend only on kernel32.dll and shell32.dll, i.e. things users already have. So I've released software with LDC 0.16.0-alpha4 Win64, and one user send me that http://i.imgur.com/xbU1VeS.png I thought it was only used for linking :( Does it also affect executable made with DMD and linked with MS linker?
Re: Threading Questions
Sorry I don't know the answers but these questions are interesting so BUMP ;) On Friday, 25 September 2015 at 15:19:27 UTC, bitwise wrote: 1) Are the following two snippets exactly equivalent(not just in observable behaviour)? a) Mutex mut; mut.lock(); scope(exit) mut.unlock(); b) Mutex mut; synchronized(mut) { } Will 'synchronized' call 'lock' on the Mutex, or do something else(possibly related to the interface Object.Monitor)? Don't know. Is this Object monitor a mutex or something else? 6) Does 'shared' actually have any effect on non-global variables beside the syntactic regulations? Don't think so.
Re: Do users need to install VS runtime redistributable if linking with Microsoft linker?
On Tuesday, 22 September 2015 at 09:38:12 UTC, thedeemon wrote: I think they don't. Generated .exe seems to depend only on kernel32.dll and shell32.dll, i.e. things users already have. Great then.
OS minimum version
1. What is the minimum Windows version required by programs created with DMD? 2. What is the minimum Windows version required by programs created with LDC? 3. What is the minimum OS X version required by programs created with LDC? You would believe such information would be easy to find, but it's not.
Do users need to install VS runtime redistributable if linking with Microsoft linker?
All in the title. DMD 64-bit links with the VS linker. Do users need to install the VS redistributable libraries?
Re: OS minimum version
On Monday, 21 September 2015 at 18:47:10 UTC, anonymous wrote: On Monday 21 September 2015 14:47, ponce wrote: 1. What is the minimum Windows version required by programs created with DMD? http://dlang.org/dmd-windows.html says: "Windows XP or later, 32 or 64 bit". Thanks to all.
Re: Question about Object.destroy
On Sunday, 20 September 2015 at 17:43:01 UTC, Lambert Duijst wrote: Is it because: - The GC did decide to run and cleanup memory straight after the call to s.destroy() - An object being in an invalid state means the program segfaults when the object is used ? - Another reason.. All methods are virtual by default. My guess would be that the invalid state implies that the virtual table pointer is not valid anymore, hence the crash.
Re: Debugging D shared libraries
On Saturday, 19 September 2015 at 17:02:37 UTC, Russel Winder wrote: English and Spanish meanings of the word are very different. In UK (not sure about Canada, USA, Australia, New Zealand, South Africa,…) it is generally a somewhat derogatory term. In French it means "to rub down with abrasive paper".
Re: Tried release build got ICE, does anyone have a clue what might cause this?
On Friday, 18 September 2015 at 22:54:43 UTC, Random D user wrote: So I tried to build my project in release for the first time in a long while. It takes like 25x longer to compile and finally the compiler crashes. It seems to go away if I disable the optimizer. I get: tym = x1d Internal error: backend\cgxmm.c 547 Does anyone have a clue what might trigger this? I'm asking because my project has grown a bit and I don't really have any good way of isolating this. I'm using dmd 2.068.1 and msvc x64 target. As a backend ICE is is very important that you report this. To workaround, try disabling inlining or -O selectively.
Re: How do you get the min / max of two numbers a, b?
On Saturday, 19 September 2015 at 03:53:12 UTC, Enjoys Math wrote: I know there's fmax for floats, but what about ints? Thanks. http://p0nce.github.io/d-idioms/#Minimum-or-maximum-of-numbers
Re: broken program, silly error messages, dub
On Saturday, 19 September 2015 at 01:54:08 UTC, Joel wrote: I accidentally wiped off a small source file. I've been trying to put it back together. Now I get unrelated errors. I've tried resetting dub. To reset DUB state completely: - remove .dub/ directory in the project directory - remove dub.selections.json - remove the ~/.dub directory
Re: Get AA key and value type
On Saturday, 19 September 2015 at 12:50:51 UTC, Pierre wrote: So how can I get types without instance ? Thanks for help. -->8- template AATypes(T) { // todo: static assert if T is no AA type here alias ArrayElementType!(typeof(T.init.keys)) key; alias ArrayElementType!(typeof(T.init.values)) value; } -->8- Should work.
Re: Debugging D shared libraries
On Saturday, 19 September 2015 at 10:45:22 UTC, Russel Winder wrote: Calling D from Python. I have two functions in D, compiled to a shared object on Linux using LDC (but I get same problem using DMD). The sequential code: extern(C) double sequential(const int n, const double delta) { Runtime.initialize(); const pi = 4.0 * delta * reduce!( (double t, int i){ immutable x = (i - 0.5) * delta; return t + 1.0 / (1.0 + x * x); })( 0.0, iota(1, n + 1)); Runtime.terminate(); return pi; } works entirely fine. However the "parallel" code: extern(C) double parallel(const int n, const double delta) { Runtime.initialize(); const pi = 4.0 * delta * taskPool.reduce!"a + b"( map!((int i){ immutable x = (i - 0.5) * delta; return 1.0 / (1.0 + x * x); })(iota(1, n + 1))); Runtime.terminate(); return pi; } causes an immediate segfault (with LDC and DMD. I am assuming that the problem is the lack of initialization of the std.parallelism module and hence the use of taskPool is causing a problem. I am betting I am missing something very simple about module initialization, and that this is not actually a bug. Anyone any proposals? Try using an explicit TaskPool and destroying it with scope(exit). Also if using LDC, you can use global ctor/dtor to deal with the runtime. --->8- extern (C) { pragma(LDC_global_crt_ctor, 0) void initRuntime() { import core.runtime; Runtime.initialize(); } pragma(LDC_global_crt_dtor, 0) void deinitRuntime() { import core.runtime; Runtime.terminate(); } } --->8-
Re: Debugging D shared libraries
On Saturday, 19 September 2015 at 16:32:18 UTC, Russel Winder wrote: (*) ponce is arguably not the most positive or constructive name to go by. Friend call me like this IRL since forever. It seems to be a swear word in english?
Re: Debugging D shared libraries
On Saturday, 19 September 2015 at 15:42:15 UTC, Russel Winder wrote: Hummm… I now do not get a segfault, and the code runs as expected : -) but the program never terminates. :-( Where is it stuck? Also, what would I need to cover the DMD and the GDC situations? I don't know. :(
Re: Debugging D shared libraries
On Saturday, 19 September 2015 at 16:25:28 UTC, Laeeth Isharc wrote: What is the difference between shared static this and the global constructor ? Russell, if you use shared static this for dmd does it work ? Laeeth. Would like to know too. On OSX I've found that shared static this() was called by Runtime.initialize(), maybe it's different on Linux.
Re: How not to run after a DUB build ?
On Thursday, 17 September 2015 at 19:44:36 UTC, BBasile wrote: On Thursday, 17 September 2015 at 19:36:10 UTC, BBasile wrote: Each time I execute `dub.exe --build=release` (or any other the build type) DUB tries to run the project after the build. This generates often generates an error when dub process returns (and even if the build is OK) but actually I don't want DUB to run after building. Is there a switch to avoid the exexution after the build ? NVM, just get that 'build' and '--build=' are two different things. with `dub.exe build --build=release` nothing is executed... Yes, the default command is "dun run"
Re: shared array?
On Monday, 14 September 2015 at 20:54:55 UTC, Jonathan M Davis wrote: So, you _can_ have low heap allocation in a C++ program, and many people do, but from what I've seen, that really isn't the norm across the C++ community in general. - Jonathan M Davis Fully agreed, C++ in the wild often make lots of copies of data structure, sometimes by mistake (like std::vector passed by value instead of ref). When you copy an aggregate by mistake, every field itself gets copied etc. Copies copies copies everywhere.
Re: shared array?
On Sunday, 13 September 2015 at 15:35:07 UTC, Jonathan M Davis wrote: But the idea that your average D program is going to run into problems with the GC while using Phobos is just plain wrong. The folks who need to care are the rare folks who need extreme enough performance that they can't afford for the GC to _ever_ stop the world. Even in that case not all threads need to be real-time and you can do threads without GC. Honestly I think only people using microcontrollers or really constrained environments and don't have the memory have that problem. I suspect preciously few of the GC haters actually have those requirements or misrepresents the ways to avoid GC-related problems. Same arguments but there is a solution for everything: "Don't want memory overhead" => minimize heap usage, use -vgc / -profile=gc "Don't want pauses" => unregister thread + @nogc "Want shorter pauses" => minimize heap usage, use -vgc / -profile=gc "Want determinism" => ways to do that GC is basically ok for anything soft-realtime, where you already spend a lot of time to go fast enough. And if you want hard-realtime, well you wouldn't want malloc either. It's a non-problem.
Re: shared array?
On Sunday, 13 September 2015 at 17:00:30 UTC, Ola Fosheim Grøstad wrote: On Sunday, 13 September 2015 at 16:53:20 UTC, ponce wrote: GC is basically ok for anything soft-realtime, where you already spend a lot of time to go fast enough. And if you want hard-realtime, well you wouldn't want malloc either. It's a non-problem. If this was true then Go would not have a concurrent collector. I was speaking of the D language.
Re: shared array?
On Sunday, 13 September 2015 at 19:39:20 UTC, Ola Fosheim Grostad wrote: The theoretical limit for 10ms mark sweep collection on current desktop cpus is 60 megabytes at peak performance. That means you'll have to stay below 30 MiB in total memory use with pointers. 30 MiB of scannable heap. My point is that we now have the tools to reduce that amount of memory with -profile=gc
Re: class destruction
On Wednesday, 9 September 2015 at 07:19:58 UTC, Q wrote: Hi. I'm playing around with D for a while and I would like to switch. But here is one thing, I need an answer for. In the Docs is mentioned that it is not sure that the DTor of a class is called. But what if I have struct, which holds a C Handle which is destroyed as soon as the struct gets destroyed (more or less like a unique pointer) and I stick this struct into a class (because I strongly need polymorphism)? Then you have to make sure the class destruction happens and not rely on the GC. Can I be sure that the Handle is destroyed as soon as the class is destroyed? I think that yes, struct members are destroyed. But you need to make sure the class is destroyed. If so there are only two ways that come to mind: 1. the class holds only a pointer to the struct, which is unsafe since I must guarantee that the struct lives as long as the class 2. the class gets a close/finalize/destroy method (or is called with the built in destroy method), which is a absolute nogo, because it is absolutly sure that this can be forgotten. Besides, we live in 2015 and that is not C where I have to clean my code manually, so this option would be ridiculous :D I'm gratefull for any answers and ideas. I'm using the manual method after much hair-pulling: http://p0nce.github.io/d-idioms/#GC-proof-resource-class It absolutely is worse than the C++ situation, however with the above pattern leaks will be reported by the GC, which is a nice consolation prize. Alternatively, stick your class in Unique! / Refcounted! / scoped!
Re: class destruction
On Wednesday, 9 September 2015 at 14:36:24 UTC, Q wrote: But if others use my code they must think about finalizing the classes? That is very awkward. classes, yes but structs, no. I'll take a look at Rust and otherwise I will stick with C++. Thanks for you answer. :) Well, resource management is only part of the story.
Re: What is the difference between D and C++ regarding Unique, RefCounted and Scoped?
On Wednesday, 9 September 2015 at 20:17:44 UTC, cym13 wrote: This is subtly missing the main question: isn't C++-like memory management of D classes possible with Unique, RefCounted and Scoped? - Unique C++ has move semantics which make moves explicit. D's Unique is more like the deprecated C++'s auto_ptr: it has an opAssign overload that changes the owner. - RefCounted Only for D structs. std::shared_ptr works for all.
Re: What is the difference between D and C++ regarding Unique, RefCounted and Scoped?
On Wednesday, 9 September 2015 at 19:53:55 UTC, ponce wrote: Oops, posted by mistake. On Wednesday, 9 September 2015 at 19:48:00 UTC, cym13 wrote: Hi, I know C++ and D without being a C++ or D guru (I know way more about D though). When talking about memory management the problem of RAII is often mentioned along with the fact that classes use the GC. I know well the difference between structs and classes and don't want to talk about the GC here. It seems to me that just as one can manage his memory in C++ using unique_ptr, shared_ptr and basic RAII we can manage our memory using Unique, RefCounted and Scoped. My question is: what is possible in C++ that isn't in D? C++ only has a D struct equivalent so all destructors are called deterministically. It's the addition of classes that create the problems in D. C++ can also throw by value, something that D can't really do. C++ objects can be: - heap-allocated or not - have deterministic destructors or not - be polymorphic or not without much restrictions. If you find a way to have the equivalent of virtual functions and dynamic casts for structs, then all our problems are virtually solved and struct would be all we need. How come that we are getting memory debates at all on this matter if we can do the same thing? Because D has class objects as an addition, and people want to use them because they need both polymorphism and holding resources. This is a very common scenario. Not all objects need a destructor, but when one need to have a destructor called, this propagates the need for clean-up to its owner too. Hence, class objects that need deterministic destruction are very easy to come by in D programs. If there are differences is fixing them an option to have something to show to D detractors? There was a proposal to stop the GC from calling destructors, which didn't take. There was also proposals of RC classes.
Re: What is the difference between D and C++ regarding Unique, RefCounted and Scoped?
On Wednesday, 9 September 2015 at 19:48:00 UTC, cym13 wrote: Hi, I know C++ and D without being a C++ or D guru (I know way more about D though). When talking about memory management the problem of RAII is often mentioned along with the fact that classes use the GC. I know well the difference between structs and classes and don't want to talk about the GC here. It seems to me that just as one can manage his memory in C++ using unique_ptr, shared_ptr and basic RAII we can manage our memory using Unique, RefCounted and Scoped. My question is: what is possible in C++ that isn't in D? C++ only h How come that we are getting memory debates at all on this matter if we can do the same thing? If there are differences is fixing them an option to have something to show to D detractors?
Re: Access Violation while trying to use OpenGL
On Wednesday, 2 September 2015 at 18:31:32 UTC, spec00 wrote: On Wednesday, 2 September 2015 at 01:07:01 UTC, Mike Parker wrote: To compile 64-bit programs on Windows, DMD requires the Microsoft toolchain. The easiest thing to do is to install the Community Edition of Visual Studio 2013 (DMD isn't yet compatible with VS 2015). Also, you aren't using OpenGL in this example, but GLFW :) Thanks Mike! Don't forget to check your sc.ini file after that, and uncomment the relevant lines.
Re: Prefer Signed or Unsigned in D?
On Wednesday, 2 September 2015 at 21:22:59 UTC, John Carter wrote: On Wednesday, 2 September 2015 at 11:03:00 UTC, ponce wrote: Everything Bjarne said still applies equally to D code, since integer promotion is identical with C from what I understand. Hmm. What Robert Elder says also applies still. And in my world his argument about undefined behavior carries weight. I'd like to point out that while Robert Elder has remarkably documented articles, his conclusions are still contrary to most C++ experts (Bjarne, Meyers, Andrei...). Additionally, I was said weeks ago on this NG that and signed overflow in D is not actually Undefined Behaviour.
Re: Prefer Signed or Unsigned in D?
On Tuesday, 1 September 2015 at 23:06:50 UTC, John Carter wrote: C/C++ discussion here http://blog.robertelder.org/signed-or-unsigned-part-2/ D rules here... http://dlang.org/type.html#integer-promotions Everything Bjarne said still applies equally to D code, since integer promotion is identical with C from what I understand.
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? The GC is noticeable and you will probably have to minimize the heap size. Fortunately the use of -vgc and @nogc helps a lot to mitigate the pauses.
Re: Functional oriented programming in D
On Thursday, 16 July 2015 at 09:49:03 UTC, Jarl André Hübenthal wrote: Why? The syntax for delegate literals with braces is listenHTTP(settings, (req, res) { res.writeBody(Hello, World!); });
Is it legal to have a function taking two aliased slices?
Example: void process(float[] input, float[] output) { // do stuff } I'd like to sometimes have overlapping slices, and don't want the compiler to assume they do not overlap.
Re: Is it legal to have a function taking two aliased slices?
On Friday, 10 July 2015 at 13:54:47 UTC, Steven Schveighoffer wrote: On 7/10/15 9:20 AM, ponce wrote: Example: void process(float[] input, float[] output) { // do stuff } I'd like to sometimes have overlapping slices, and don't want the compiler to assume they do not overlap. Yes, it's legal, and the compiler doesn't assume anything about the two slices, including whether they overlap or not. -Steve Cool, thanks!
Re: Which XMM are safe to erase in asm{} blocks?
On Wednesday, 8 July 2015 at 05:22:34 UTC, ketmar wrote: On Tue, 07 Jul 2015 12:33:38 +, ponce wrote: Is this secret knowledge? yes. ;-) i believe that there are not so many people doing asm in D, and many of them using write and forget technique (i.e. write and don't touch if it works). so you need someone with good knowledge of backend to answer this question, and such people are rare here. ;-) so i thing that your best bet is to investigate that by yourself, and write an article about it. I would if I had time ;) It looks that using XMM0 to XMM5 doesn't blow. It would also help to know if the compiler insert spilling code if the asm code when some register is used that should not be modified by law. C++ compilers do that and it's both a performance hit and a safety net.
Re: Which XMM are safe to erase in asm{} blocks?
On Monday, 6 July 2015 at 08:54:48 UTC, ponce wrote: What registers can I safely modify in asm {} blocks? Especially XMM registers. I can't find the information on http://dlang.org/iasm.html Note that this question isn't for function-call boundaries but asm{} boundaries since I do not use naked; Bump. Is this secret knowledge?
Which XMM are safe to erase in asm{} blocks?
What registers can I safely modify in asm {} blocks? Especially XMM registers. I can't find the information on http://dlang.org/iasm.html Note that this question isn't for function-call boundaries but asm{} boundaries since I do not use naked;
Re: code review based on what I learned from D
On Sunday, 5 July 2015 at 06:53:36 UTC, Szabo Bogdan wrote: you don't want to crash the user app, because this will make the user unhappy. This type reasoning is always flawed. It's like saying that the Earth is flat. http://p0nce.github.io/d-idioms/#Unrecoverable-vs-recoverable-errors
Re: Porting from D1 to D2
On Sunday, 28 June 2015 at 21:26:52 UTC, Walter Bright wrote: On 6/28/2015 2:48 AM, ponce wrote: I don't quite get what code could be generating that reference, since I don't call format or toString on a Throwable. You can grep the .obj files for the symbol. Thanks. Fixed by upgrading. I think I had messed up sc.ini.
Porting from D1 to D2
I have a program that is almost ported from D1 to D2 but there is still a problem with a reference to object.Throwable.toString(scope void delegate(in string) sink); With OPTLINK (32-bit): Error 42: Symbol Undefined _D6object9Throwable8toStringMxFMDFxAyaZvZv (const(void function(scope void delegate(const(immutable(char)[] object.Throwable.toString) With link.exe (64-bit): vibrant_derelict.lib(exception_311_6db.obj) : error LNK2001: unresolved external symbol _D6object9Throwable8toStringMxFMDFxAyaZvZv vibrant_derelict.lib(exception_314_c30.obj) : error LNK2001: unresolved external symbol _D6object9Throwable8toStringMxFMDFxAyaZvZv vibrant_derelict.lib(exception_312_89d.obj) : error LNK2001: unresolved external symbol _D6object9Throwable8toStringMxFMDFxAyaZvZv vibrant_common2.lib(error_a0_4d3.obj) : error LNK2001: unresolved external symbo l _D6object9Throwable8toStringMxFMDFxAyaZvZv vibrant_common2.lib(error_9e_2e1.obj) : error LNK2001: unresolved external symbo l _D6object9Throwable8toStringMxFMDFxAyaZvZv vibrant_common2.lib(error_9f_461.obj) : error LNK2001: unresolved external symbo l _D6object9Throwable8toStringMxFMDFxAyaZvZv vibrant_derelict.lib(exception_313_a31.obj) : error LNK2001: unresolved external symbol _D6object9Throwable8toStringMxFMDFxAyaZvZv vibrant.obj : error LNK2001: unresolved external symbol _D6object9Throwable8toSt ringMxFMDFxAyaZvZv vibrant_common2.lib(state_eb9_2ed.obj) : error LNK2001: unresolved external symb ol _D6object9Throwable8toStringMxFMDFxAyaZvZv vibrant_common2.lib(error_9d_42f.obj) : error LNK2001: unresolved external symbo l _D6object9Throwable8toStringMxFMDFxAyaZvZv vibrant_common2.lib(error_a1_398.obj) : error LNK2001: unresolved external symbo l _D6object9Throwable8toStringMxFMDFxAyaZvZv .dub\build\application-debug-windows-x86_64-dmd_2067-A5A845EF2ABB6AC157FC78217DE 83EB9\vibrant.exe : fatal error LNK1120: 1 unresolved externals I don't quite get what code could be generating that reference, since I don't call format or toString on a Throwable. Anyone has experience with this?
Re: Clean way to tell whether a destructor is called by the GC
On Wednesday, 13 May 2015 at 11:24:10 UTC, Kagamin wrote: On Tuesday, 12 May 2015 at 12:53:59 UTC, ponce wrote: I already have such a dispose() function. The problem is that to support Unique! and scoped! and friends, the destructor must call dispose(). Thus my need for a way to separate the GC-induced destructors within dispose() or ~this (same problem). Maybe it's simpler to copy-paste Unique and scoped and modify them to handle disposable objects? But then we would need a standardized name (some use close, some use dispose, some use release) The closest thing we have to a standardized function name is the destructor.
Clean way to tell whether a destructor is called by the GC
I need a robust isCalledByGC function to leak intentionally when a destructor is called as a result of the GC. It is a way to enforce deterministic destruction without ever relying on accidental correctness. class A { ~this() { if(iscalledByGC()) { [leak and write an error to stderr] } else { [normal release of resources] } } } Prior solution: http://forum.dlang.org/post/li2oj4$1avo$1...@digitalmars.com but that involves modifying the runtime.
Re: Clean way to tell whether a destructor is called by the GC
On Tuesday, 12 May 2015 at 12:31:35 UTC, Adam D. Ruppe wrote: Let me suggest a completely different option: make a destructor that works while the GC is running by managing the resources manually in both construction and destruction. I see, but not all ressources can be disposed by any thread. I'd prefer to make it an error. Also, relying on GC destructors can make a program work by mistake. isn't *all* reference types that are problematic to access, it is just GC managed references. So anything from a C function is cool. Otherwise, accessing the runtime variable seems ok to me like the link said, hacky sure, but it'd work nothing else comes to mind, other than using a separate dispose() method when you delete it manually and leave the dtor for only the GC. I already have such a dispose() function. The problem is that to support Unique! and scoped! and friends, the destructor must call dispose(). Thus my need for a way to separate the GC-induced destructors within dispose() or ~this (same problem).
Re: GC has a barbaric destroyng model, I think
On Thursday, 12 February 2015 at 08:14:49 UTC, Mike Parker wrote: On 2/12/2015 6:42 AM, ketmar wrote: this problem has very easy solition: we should stop calling class dtors destructors, and rename them to finalizers. Absolutely. So many people coming from C++ see destructor and want to use them as they did in C++. How often do we see people coming on here wondering why they can't get deterministic destruction out of class destructors? Of course, it's too late to change anything now, but we need a big, obvious link from the docs and the wiki and anywhere else people can read about destructors to a page that explains how D class destructors are not C++ class destructors. http://p0nce.github.io/d-idioms/#The-trouble-with-class-destructors I've also made one for D can't do real-time because it has a stop-the-world GC http://p0nce.github.io/d-idioms/#The-impossible-real-time-thread And one for D doesn't have ADTs http://p0nce.github.io/d-idioms/#Recursive-Sum-Type-with-matching
Re: GC has a barbaric destroyng model, I think
On Thursday, 12 February 2015 at 09:50:39 UTC, ketmar wrote: On Thu, 12 Feb 2015 09:04:27 +, ponce wrote: http://p0nce.github.io/d-idioms/#The-trouble-with-class-destructors I've also made one for D can't do real-time because it has a stop-the-world GC http://p0nce.github.io/d-idioms/#The-impossible-real-time-thread And one for D doesn't have ADTs http://p0nce.github.io/d-idioms/#Recursive-Sum-Type-with-matching i believe that yor work needs more official highlighting. maybe it worth having the links right on the front page of dlang.org Thanks :) but I'm not 100% sure about the correctness of it all. More like 80% :|.
Re: GC has a barbaric destroyng model, I think
On Thursday, 12 February 2015 at 10:24:38 UTC, Mike Parker wrote: On 2/12/2015 6:09 PM, weaselcat wrote: On Thursday, 12 February 2015 at 08:33:35 UTC, Kagamin wrote: Truth be told, D has no guideline for deterministic destruction of managed resources. +1 don't complain about people wondering why class destructors don't work when there's no _real_ way to do it in D beyond 'drop down to C level and get going.' D is absolutely horrid for resource management. I'm not complaining. I'm simply suggesting that the very word destructor likely plays a role in the misconception that class destructors behave as they do in C++. However, I do think that when moving from one language to another, there has to be a certain expectation that things are going to be different and it shouldn't be a surprise when they are. What I think is that the GC should simply never call the destructors. The GC calling class destructors is currently a 50% solution that provide illusory correctness.
Re: Better native D 2D graphics library?
On Saturday, 7 February 2015 at 22:09:03 UTC, Gan wrote: Is there a better D graphics library in the works? I'm using SFML(which is very easy and has lots of features) but it seems to use a lot of ram(if you leave it running for a while on a graphic intensive scene) and trying to make it include the dependencies with the compiled executable is complicated. Is there a D 2D graphics library that's just as easy, cross platform, doesn't use X11, allows drawing to off-screen buffers and drawing those to screen? (plus supports nice drawing of shapes, circles, rectangles, lines) I'm probably asking too much- I doubt such a thing exists. SDL 2.x can do that with renderers.
Re: How to ensure a thread cannot be blocked by the GC?
On Thursday, 4 December 2014 at 02:01:26 UTC, Ola Fosheim Grøstad wrote: On Thursday, 4 December 2014 at 01:36:13 UTC, Ola Fosheim Grøstad wrote: So I suppose none of your threads are suspended unless you suspend it with Thread on call_back entry? But why suspend a @nogc thread? What a mess of incorrect recollection and typos (it is late, 3AM :-P): I meant to say that I suppose none of your threads are suspended unless you register it as a Thread Thanks Ola Jacob. In fact I was registering them both with core.sys.windows.dll.dll_thread_attach() when callbacked with DLL_THREAD_ATTACH, but I see now that I should instead register to the runtime only the interruptible thread. Made-up problem!
Re: How to ensure a thread cannot be blocked by the GC?
On Wednesday, 3 December 2014 at 22:53:48 UTC, ponce wrote: I have a DLL written in D that gets called by two different threads, created by a non-D host program (audio plugin). I did not create those threads, but my understanding is that they get attached to the D runtime. Thread A is a real-time callback and should not ever block. @nogc seems perfect for this. Thread B and it's impractical to make it @nogc. How to ensure that a collection triggered by thread B never stop thread A in stop the world collections? Correction: Thread B isn't real-time, allocates, and it's impractical to make it @nogc.
How to ensure a thread cannot be blocked by the GC?
I have a DLL written in D that gets called by two different threads, created by a non-D host program (audio plugin). I did not create those threads, but my understanding is that they get attached to the D runtime. Thread A is a real-time callback and should not ever block. @nogc seems perfect for this. Thread B and it's impractical to make it @nogc. How to ensure that a collection triggered by thread B never stop thread A in stop the world collections?
Re: Audio file read/write?
COn Friday, 7 November 2014 at 02:58:15 UTC, Daren Scot Wilson wrote: What's the current recommended way to read and write audio files? I don't need to play it on the speakers or deal with anything real time - just read a file's data into an array, fiddle with it, and write it out to a file. I found some other threads about audio files, but none recent, mentioning SDL and OpenAL. Are these still the way to go? I'm thinking I should avoid SDL since it does far more than audio, none of which I care about. OpenAL also does way more than I care about, but at least is just audio. SDL vanilla and OpenAL won't help with reading and writing audio files. For my application, I need to read a few of the common formats, such as .wav, .au, .mp3, .ogg and whatever else is popular. I only need to write .wav but other audio tinkerers may want to write other formats. wave-d: read/write .WAV file, all at once https://github.com/d-gamedev-team/wave-d Pretty sure libsndfile can read .wav, .au, .ogg but not mp3 No commercial usage unless you pay a licence. https://github.com/p0nce/DerelictSndFile.git BASS can do it all: No commercial usage unless you pay a licence. https://github.com/p0nce/DerelictBASS SDL_mixer can read .wav .au .ogg and .mp3 https://github.com/DerelictOrg/DerelictSDL2
Re: D int and C/C++ int etc not really compatible when interfacing to C/C++
On Sunday, 2 November 2014 at 12:37:13 UTC, Mike Parker wrote: On 11/2/2014 8:59 PM, Marc Schütz schue...@gmx.net wrote: On Saturday, 1 November 2014 at 21:00:54 UTC, Kagamin wrote: D claims compatibility with system C compiler, which usually have 32-bit int. ... and for C/C++ long which can be 32 or 64 bit, DMD recently introduced the types c_long and c_ulong. (Not released yet.) Those aren't new. They have been in core.stdc.config for quite some time. c_long and c_ulong get used, should c_int and c_uint too in bindings? Looks like fringe use case.
Recursive data-types
I'm dabbling with Scheme interpreter and ultimately I would need to declare the following types. -- struct Function { Environment env; Atom params; Atom body_; } // An atom is either a string, a double, a symbol, a function or a list of atoms alias Atom = Algebraic!(string, double, Symbol, Function, This[]); -- These definitions can't work since Function and Atom need each other in this recursive definition. How to get out of this trap? Do I have to drop Algebraic and go back to manual tagged unions?
Re: Recursive data-types
On Saturday, 27 September 2014 at 11:40:19 UTC, Rikki Cattermole wrote: How to get out of this trap? Do I have to drop Algebraic and go back to manual tagged unions? Converting Function to a class. No where near ideal. But it'll work. It does work! Thanks. Actually it's quite appropriate to make it a reference type.
Re: Recursive data-types
On Saturday, 27 September 2014 at 14:08:18 UTC, H. S. Teoh via Digitalmars- What about using Atom*[] instead of Atom[]? Atom[] seems simpler to me.
Re: Recursive data-types
On Saturday, 27 September 2014 at 15:45:20 UTC, Meta wrote: Also, you might want to use This* instead of This[], unless you want an Atom to be able to contain a whole array of other atoms. That's indeed what I want.
Re: Strange segfault (Derelict/OpenGL)
On Friday, 29 August 2014 at 11:23:34 UTC, Robin Schroer wrote: I'm not entirely sure where to post, so I will put it here. I'm playing around with D and Derelict 3 to make something with OpenGL (don't really know what yet). I managed to open a window, add an OpenGL context, clear the screen and flip buffers. But as soon as I try to render a triangle, my program crashes. As John Colvin said, forgetting to call DerelictGL3.reload() is a common error.
Cross-module inlining with separate compilation?
Is there a way to have cross-module inlining but with separate compilation? Like with link-time generation in C++ compilers.
Re: Programming a Game in D? :D
On Saturday, 2 August 2014 at 20:38:59 UTC, David wrote: Hi, not too sure if there's still someone reading this post, but i do have another question. So, I heared so much good stuff about D, it's powerfull, fast the syntax is nice, but well, why is D actually not used for common games yet? (I mean I know about some smaller projects, but nothing big) A lot of commercial game middleware is already written in C++. Without such third-party libs, it's hard to make a AAA games. Linking to C++ middleware is way easier if your game is in C++ itself. C++ programmers are accustomed to C++ and the ones who weren't flocked to Java, C#, whatever.
Re: Extended math library
On Wednesday, 16 July 2014 at 21:12:00 UTC, bachmeier wrote: Have you tried them? Do they work? I couldn't get scid to work last year. I've never heard of dstats before, but it hasn't seen any activity in two years. I'd be surprised if it worked with the latest release of DMD. Can't speak for scid, but dstats shouldn't be hard to bring up-to-date.
Re: is there a way to pause a program and resume with just a key press (or enter key)
I don't know about Windows, but on Linux, you can just press ctrl-s and ctrl-q to pause/resume the console. (This is a Linux terminal function, not specific to D.) In the Windows shell, the pause key will halt a program and return will resume it.
Re: Extended math library
On Tuesday, 15 July 2014 at 20:46:32 UTC, Martijn Pot wrote: To make a long story short: Is there any math library with e.g. mean, std, polynomial fitting, ...? https://github.com/kyllingstad/scid https://github.com/dsimcha/dstats
Undo struct slicing by type-punning
Hi, I am porting C++ code that undo Object Slicing by casting const-references: http://en.wikipedia.org/wiki/Object_slicing My translation in D Code struct A { // stuff } struct B { A a; alias a this; // stuff } void myFunction(ref const(A) a) { if (a-is-actually-a-B) { // here goes the converstion to a B reference myFunction2(*cast(const(B)*)(a)); // using pointer to do type-punning } } To do this, I need to by guaranteed an object passed through ref const(A) is never, ever passed by value. Is it safe to assume?
Re: Undo struct slicing by type-punning
Ok, solved it, I just use pointer casts and it seems to work when the struct is sliced. On Monday, 14 July 2014 at 13:23:57 UTC, ponce wrote: Hi, I am porting C++ code that undo Object Slicing by casting const-references: http://en.wikipedia.org/wiki/Object_slicing My translation in D Code struct A { // stuff } struct B { A a; alias a this; // stuff } void myFunction(ref const(A) a) { if (a-is-actually-a-B) { // here goes the converstion to a B reference myFunction2(*cast(const(B)*)(a)); // using pointer to do type-punning } } To do this, I need to by guaranteed an object passed through ref const(A) is never, ever passed by value. Is it safe to assume?
Re: Undo struct slicing by type-punning
On Monday, 14 July 2014 at 18:43:36 UTC, Ali Çehreli wrote: On 07/14/2014 10:35 AM, ponce wrote: Ok, solved it, I just use pointer casts and it seems to work when the struct is sliced. I think there is a terminology issue here. Slicing cannot be undone; once the object is sliced, the non-A parts are gone. Well they are not really gone if the struct is passed by-ref, you can recover the gone parts: http://dpaste.dzfl.pl/d64863fd4c6d
Re: Undo struct slicing by type-punning
On Monday, 14 July 2014 at 18:43:36 UTC, Ali Çehreli wrote: It is guaranteed by the language spec that yes, myFunction() takes an A by reference. However, you can't know where that A is coming from; so, the safety of that cast is up to you. Consider: void foo(A a) // -- Already sliced { myFunction(a);// -- Will perform invalid cast } Indeed, the code I port do that because struct have a type-tag.
Re: DUB help plz
On Thursday, 3 July 2014 at 04:46:02 UTC, K.K. wrote: Is the only thing I'm missing the .dll's? Thanks! Yes, everything went fine, and you find the missing DLL here: https://www.libsdl.org/download-2.0.php
Re: Source transformation for D
On Thursday, 3 July 2014 at 10:17:59 UTC, Kashyap wrote: Hi, Is there a source transformation for D available? Could someone please point me to it? If not, I'd like to work on one - I'd appreciate any pointers on getting started. I am considering writing the whole thing in D and not relying the lexer/parser in C that is already there. Regards, Kashyap https://github.com/Hackerpilot/Dscanner https://github.com/deadalnix/SDC
Re: integer out of range
On Thursday, 3 July 2014 at 10:15:25 UTC, pgtkda wrote: why is this possible? int count = 50_000_000; int is always 4 bytes, it can contains from -2_147_483_648 to 2_147_483_647.
Re: What is best way to communicate between computer in local network ?
On Friday, 27 June 2014 at 12:51:45 UTC, bioinfornatics wrote: Hi, I have a linux network and i would like to know if they are a D library to communicate between computer efficiently. I do not know if that is better to use websocket and if they exists into dlang: - http://planet.jboss.org/post/rest_vs_websocket_comparison_and_benchmarks Thanks for your help Regards Not efficient in any means, but DHSL allows to create super simple webservers. https://github.com/canidae/DHSL
Re: Programming a Game in D? :D
On Thursday, 22 May 2014 at 15:39:36 UTC, David wrote: Hey, I'm really new to D, and pretty new to programming overall too, But I want to make a 3d Game, (just sth. small). I really like D and want to do it in D, but in the Internet there is no shit about programming a game in D ^^ Is there any engine written in D? For example the CryEngine is for C++, so I would have to write a wrapper? So, how do I write a wrapper? I would need a wrapper for DirectX too right? Are there any wrappers ore Engines for D i can use? btw. I know I dont write that in 1 day ^^ Are there any tutorials or sth. on Programming a Game in D? S I just wanna come as far to have a little Cube where i can run around on with a few phisics :) so just the startup to load a world and so on Thanks in advance :) And sry my english sucks :D Hi David, Learning programming, learning D and learning 3D are 3 significant endeavours. You might want to begin with http://www.basic4gl.net/ which will get you going with 3D, quite a topic in itself. Then learn D regardless :)
Re: Video playback
On Sunday, 18 May 2014 at 07:10:29 UTC, Dmitry wrote: Hi everyone! I want to play video in my D-application (maybe WebM or Theora). However didn't find any library for operation with video in D. I am a beginner in D, experience of transfer of libraries with C/C++, certainly isn't present. Maybe somebody will prompt something? P.S. My application uses SFML (DSFML). If you can ensure the host machine will have ffmpeg installed, you can do it like AE does: https://github.com/CyberShadow/ae/blob/master/utils/graphics/ffmpeg.d