Idea/request: If you have a DUB project, add a code.dlang.org badge to README
A few weeks/months ago someone here mentioned that it'd be good if DUB projects linked to code.dlang.org to help anyone who runs into such a project quickly discover other D projects. MAny GitHub projects have badges/shields on top of their READMEs - little image strips showing things like continuous integration status, code coverage, etc. There's also a service generating these: shields.io I generated a simple listed at| code.dlang.org shield, and added it to my project READMEs as a link pointing to code.dlang.org for example, see D:YAML README: https://github.com/kiith-sa/D-YAML You can do the same by either linking to or downloading the shield: https://img.shields.io/badge/listed%20at-code.dlang.org-red.png (used red... because mars) and putting the image (whether as a link to shields.io or your own copy) into your README. It's not likely to be a huge improvement, but I expect it *can* help people notice more D projects and it's trivial to do.
Re: Idea/request: If you have a DUB project, add a code.dlang.org badge to README
On Tuesday, 30 December 2014 at 21:19:52 UTC, jklp wrote: On Tuesday, 30 December 2014 at 21:12:38 UTC, Kiith-Sa wrote: A few weeks/months ago someone here mentioned that it'd be good if DUB projects linked to code.dlang.org to help anyone who runs into such a project quickly discover other D projects. MAny GitHub projects have badges/shields on top of their READMEs - little image strips showing things like continuous integration status, code coverage, etc. There's also a service generating these: shields.io I generated a simple listed at| code.dlang.org shield, and added it to my project READMEs as a link pointing to code.dlang.org for example, see D:YAML README: https://github.com/kiith-sa/D-YAML You can do the same by either linking to or downloading the shield: https://img.shields.io/badge/listed%20at-code.dlang.org-red.png (used red... because mars) and putting the image (whether as a link to shields.io or your own copy) into your README. It's not likely to be a huge improvement, but I expect it *can* help people notice more D projects and it's trivial to do. red is connoted negative/agressive, I think blue would be better. Or maybe yellow-mustard for those who have doubtful tastes... If you want blue, just replace red with blue. I used red because it's the color of the D logo, site and the color of Mars (as D was originally called Mars and lot of D things are named after Mars, e.g. Phobos/Deimos etc.)
Re: Idea/request: If you have a DUB project, add a code.dlang.org badge to README
On Tuesday, 30 December 2014 at 21:19:52 UTC, jklp wrote: On Tuesday, 30 December 2014 at 21:12:38 UTC, Kiith-Sa wrote: A few weeks/months ago someone here mentioned that it'd be good if DUB projects linked to code.dlang.org to help anyone who runs into such a project quickly discover other D projects. MAny GitHub projects have badges/shields on top of their READMEs - little image strips showing things like continuous integration status, code coverage, etc. There's also a service generating these: shields.io I generated a simple listed at| code.dlang.org shield, and added it to my project READMEs as a link pointing to code.dlang.org for example, see D:YAML README: https://github.com/kiith-sa/D-YAML You can do the same by either linking to or downloading the shield: https://img.shields.io/badge/listed%20at-code.dlang.org-red.png (used red... because mars) and putting the image (whether as a link to shields.io or your own copy) into your README. It's not likely to be a huge improvement, but I expect it *can* help people notice more D projects and it's trivial to do. red is connoted negative/agressive, I think blue would be better. Or maybe yellow-mustard for those who have doubtful tastes... aand what I was supposed to post (I didn't itend to put this in D.learn): http://forum.dlang.org/thread/tbspahcinalabopfb...@forum.dlang.org#post-tbspahcinalabopfbxey:40forum.dlang.org
Re: Hunting down rogue memory allocations?
On Friday, 3 October 2014 at 08:18:45 UTC, thedeemon wrote: On Thursday, 2 October 2014 at 20:16:56 UTC, Gary Willoughby wrote: Say i have created a program written in D, what tools are available for me to track memory allocations? I wrote a tiny module trackallocs.d that inserts a GC proxy and outputs to log file (or stdout) all the allocations, gathering some stats. You can turn tracking on and off in any place of your code. Used it before 2.066 where @nogc appeared to check whether my code was allocation-free. Current version works in both 2.066 and earlier versions. Find it here: https://bitbucket.org/infognition/dstuff/src/ Inside it uses one hack based on knowledge of D runtime internals, so in future versions of D runtime, if Proxy struct changes again, it may need to be changed as well. This is really cool stuff, I needed something like this but didn't know it was possible. Mind if I use some parts of it in my profiler? (there's no license)
Re: Hunting down rogue memory allocations?
On Thursday, 2 October 2014 at 20:16:56 UTC, Gary Willoughby wrote: Say i have created a program written in D, what tools are available for me to track memory allocations? If you write a program and its performance is slow because you suspect too many allocations are taking place in unrecognised areas, what tools or techniques do you use to find where they are and eliminate them? If *time* spent by allocations is a problem, profile with `perf top` (assuming you have Linux): Look for 'gc', 'malloc', 'calloc', etc. (Plain perf record will also work, but not be as quick/interactive. CodeXL works too.) See https://perf.wiki.kernel.org/index.php/Tutorial - you probably need some specific arguments to get caller info, didn't use it for a while so I don't remember. If e.g. the GC is an issue, it should be immediately evident with some GC function taking e.g. over 5% of time. Usually the actual overhead will be much higher but divided into multiple smaller functions that will take little time individually. Drill down into one of these and look at its callers. Eliminate the most common source of calls, look again, repeat. Usually removing a source of alloc calls will result in better speedup than the profiler suggests. If *space* is a problem, Valgrind doesn't work with most D programs for some reason (probably D's fault), so, good luck with that. But eliminating the biggest time wasters usually helps space as well (or rather, it makes it more controllable as you know better where you allocate memory).
Re: How to get nogc to work with manual memory allocation
On Sunday, 24 August 2014 at 08:03:11 UTC, Bienlein wrote: Hello, I was having a look at the new nogc annotation and therefore wrote some code that creates an instance on the heap bypassing the GC (code adapted from http://dpaste.dzfl.pl/2377217c7870). Problem is that calls to call the class' constructor, destructor and others can't be called anymore once nogc is used. So the question is how to get manual allocation and deallocation done with using nogc. Here is the experimental code: @nogc T nogcNew(T, Args...) (Args args) { import std.conv : emplace; import core.stdc.stdlib : malloc; // get class size of class object in bytes auto size = __traits(classInstanceSize, T); // allocate memory for the object auto memory = malloc(size)[0..size]; if(!memory) { import core.exception : onOutOfMemoryError; onOutOfMemoryError(); } // call T's constructor and emplace instance on // newly allocated memory return emplace!(T, Args)(memory, args); } @nogc void nogcDel(T)(T obj) { import core.stdc.stdlib : free; // calls obj's destructor destroy(obj); // free memory occupied by object free(cast(void*)obj); } @nogc void main() { TestClass test = nogcNew!TestClass(); test.x = 123; nogcDel(test); test.x = 456; // no protection violation ?! // remove @nogc to run this TestClass t = new TestClass(); t.x = 789; delete t; t.x = 678; // protection violation as expected } I have omitted the code for the TestClass class to save space. Problem is that the compiler outputs this: Error: @nogc function 'main.nogcNew!(TestClass, ).nogcNew' cannot call non-@nogc function 'core.exception.onOutOfMemoryError' Error: @nogc function 'main.nogcNew!(TestClass, ).nogcNew' cannot call non-@nogc function 'std.conv.emplace!(TestClass, ).emplace' Error: @nogc function 'main.nogcDel!(TestClass).nogcDel' cannot call non-@nogc function 'object.destroy!(TestClass).destroy' Is there a way to get around this? Then the test.x = 456; did not cause a protection violation although the instance was deallocated before calling nogcDel. Something with the deallocation in nogcDel seems not to work. Some hint appreciated on this. When calling delete t the protection violation happens on the next line as expected. Thanks a lot, Bienlein @nogc is *no GC*, it has nothing to do with where you allocate from, no matter how some would choose to interpret it (I use it to mean 'no heap' pretty often in my own projects, though, can be useful). You can mark it @nogc by wrapping the non-@nogc stuff in a function and casting it, but you *absolutely* must be sure GC is not used in any called functions. You could possibly do that by requiring T's constructor to be @nogc, not sure if the other functions can use GC or not. Also, your function seems to be written only for classes, if this is intended, you should have an if(is(T == class)) template constraint there.
Re: Non-GC based List/Set/Map implementation?
On Tuesday, 26 August 2014 at 10:38:47 UTC, Bienlein wrote: Hello, does anyone know of a List/Set/Map implementation that does not rely on the GC? The would be the last thing I need for D to be really happy with it ;-) Thanks, Bienlein These use the work-in-progress std.allocator and seem to be more maintained, although they don't seem to take advantage of DMD 2.066 (@nogc) yet: https://github.com/economicmodeling/containers
Re: Learning D
On Monday, 25 August 2014 at 16:46:11 UTC, Ryan wrote: Me: Software developer for 30 years. So perhaps this is old fashion, but I wanted to start using D by whipping together nice little personal utilities. I tried installing MonoDevelop and Mono-D. I can't even figure out the basics, such as adding references to a project. There are no options in the context menus, and although it looks like drag an drop might work (a '+' sign appears by the cursor), dropping a file from the filesystem doesn't work either. Although I dream of someday being able to add a reference to a project, I'm not really sure what I might drag in. I managed to download and compile GtkD, since it seems like a GUI would be a nice place to start (again, old fashion). I got three *.lib files out of it... H... Maybe these are references?? I had installed the Visual Studio plugin, but I don't want to use this since I would like to eventually migrate away from Windows. Let me cut to the chase. I have no friggin' clue how to start, and I can't seem to find a tutorial anywhere... What IDE should I use? I'm not big fan of Eclipse, although if I had to use it this wouldn't be a dealbreaker. Give me something easy and lightweight, unless you've got a GUI builder (this is why I started with MonoDevelop, though this isn't working so well for me). What Widget library should I use? I started with GTKD, but since there are no tutorials does this mean nobody actually does this? Should I use DWT? What about QT? I just want something simple and mainstream to start learning D with. Any thoughts? I don't use an IDE, but MonoD seems to be the most recommended cross-platform option. It has a wiki page here if it helps: http://wiki.dlang.org/Mono-D I recommend only using an IDE that uses DUB (http://code.dlang.org/about), which is becoming the de facto standard for building D projects, and is cross-IDE, allowing you to move between IDEs and to work with developers using other IDEs. MonoD probably uses this, as does DDT(Eclipse). I have no idea what interface MonoD or other IDEs offer for DUB, but DUB uses a 'dub.json' file where you specify libraries you use and their versions. DUB will automatically download the libraries when you compile the project. Available DUB packages (libraries/apps) are listed at http://code.dlang.org . That is probably also the best list of D libs we have at the moment, although many projects are not there yet. Only use DWT if you like Java-style code. QtD is not in usable state yet. GtkD should be good, better for 'big' apps (i.e. more features), TkD for simple ones (simpler to use). To learn about the language itself, this (free) book is really good: http://ddili.org/ders/d.en/index.html
Re: struct or class
On Sunday, 24 August 2014 at 11:56:44 UTC, nikki wrote: I come from languages that don't offer structs, I have this json load function that has to keep some data and intuitively I've written a struct, I've read about the differences, heap vs stack, value vs reference, but know I think i am overthinking it. Is this decent: bool loadFromFile (string path) { auto data = readText(path); JSONValue parsed = parseJSON(data); struct AtlasSpriteData { SDL_Rect clipRectangle; int xOffset; int yOffset; } AtlasSpriteData[string] dict; foreach( string name, value; parsed[frames] ){ SDL_Rect clipRectangle; auto spriteSourceSize = value[spriteSourceSize]; clipRectangle.x = to!int(frame[x].toString()); clipRectangle.y = to!int(frame[y].toString()); clipRectangle.w = to!int(frame[w].toString()); clipRectangle.h = to!int(frame[h].toString()); int xOffset = to!int(spriteSourceSize[x].toString()); int yOffset = to!int(spriteSourceSize[y].toString()); auto data = AtlasSpriteData(clipRectangle, xOffset, yOffset); dict[name] = data; } Or should I use a class for that AtlasSpriteData? reading about it I get the impression everytime I'll look up data from that dictionary data will get copied ? In this case class makes sense (assuming AtlasSpriteData has few instances that will be shared around a lot). But you could also use a pointer to a struct, especially if you manually allocate it and want to avoid the GC. Also, you can read data from the associative array by reference (basic example, no error checking): ref AtlasSpriteData spriteData(string name) { return dict[name]; }