Re: DerelictGL3 glGenBuffers segmentation fault.
On Sunday, 24 December 2017 at 05:23:12 UTC, Mike Parker wrote: If you are going to use glFreeFuncs like this, you can't import opengl that way. As per the DerelictGL3 documentation [1], the simplest way to make this work is to implement a module that publicly imports derelict.opengl and declares the mixin, then import that module elsewehre. In case that wasn't clear, make sure to replace every current instance of `import derelict.opengl` with `import mygl`, or whatever you happen to name the module.
Re: DerelictGL3 glGenBuffers segmentation fault.
On Sunday, 24 December 2017 at 03:00:16 UTC, Kevin wrote: On Sunday, 24 December 2017 at 01:42:58 UTC, Mike Parker wrote: I've found the problem. But first... I making a simple static library. I don't see a static library anywhere. You weren't "importing a static library", something which isn't possible in D anyway. You import modules, not libraries. The reason it worked in your main source file (cube.d) and not in your buffers module is this line: mixin glFreeFuncs!(GLVersion.gl33); You have that in cube.d, but in buffers.d you have this: import derelict.opengl; If you are going to use glFreeFuncs like this, you can't import opengl that way. As per the DerelictGL3 documentation [1], the simplest way to make this work is to implement a module that publicly imports derelict.opengl and declares the mixin, then import that module elsewehre. So the first step to making your code work is this: ``` module mygl; public import derelict.opengl; mixin glFreeFuncs!(GLVersion.GL33); ``` That's not all, though. The documentation also explicitly says you have to define the DerelictGL3_CustomFreeFuncs version when you compile. So add this to your dub.json: ``` "versions": [ "DerelictGL3_CustomFreeFuncs" ], ``` That should at least get you compiling. But your dependency declarations have a couple of issues that need fixing. Currently, you have this: ``` "derelict-sdl2": "~>3.0", "derelict-gl3": "~2.0", ``` Your sdl2 dependency is syntactically correct, but what it says is that you're happy with any version of DerelictSDL2 from 3.0.x to 3.9.x, inclusive. The result is that you're actually getting version 3.1.0-alpha.3. In the near future, I'll be updating for SDL 2.0.7 and will add a new 3.2.0-alpha.1 version. If you run `dub upgrade` at that point, you'll get that version. That's a bad idea! What you want to do is to specify the full version, major.minor.path, 3.0.0. And, since there is a 3.0.0-beta and not a 3.0.0, you'll need to append -beta. The same applies to your gl3 dependency, but you have another problem there. The syntax is incorrect: ~2.0 instead of ~>2.0. ~foo tells dub to look for a git branch with the name "foo" -- and it's deprecated syntax. Since there happens to be a branch in the DerelictGL3 github repo named "2.0", that's what you're actually getting. So you should update your dependencies to look like this: ``` "derelict-sdl2": "~>3.0.0-beta", "derelict-gl3": "~>2.0.0-beta", ``` Be sure to delete your dub.selections.json after editing and before you rebuild. With these, you'll be compiling and properly upgrading in the future if you need to. [1] http://derelictorg.github.io/packages/gl3/
Re: Compile to non-OS binary
On Sunday, 24 December 2017 at 03:15:58 UTC, Amorphorious wrote: In fact, it would be very helpful to have switches that disable the various "features" of D that I will not use rather than having to do any self compilation. The way I did it was create a custom runtime only including the features I wanted, then use `-defaultlib=` to disable linking in the library.. There's also the `-betterC` switch that will skip things like this too. This is my old code, but emphasis on old, I haven't updated it for over a year and runtime hacks like this tend to need tweaks to keep working http://arsdnet.net/dcode/minimal.zip I believe gdc also has several flags to disable individual features.
Re: Compile to non-OS binary
Premature send(tabs?!?! ;/) void main() { version(BIOS) { import iBIOS; BIOSOut("Hello World"); } else { writeln("Hello World"); } } When compiled appropriately will create a bootable executable that displays the string. Else will create an OS specific executable that prints the string. (for demo purposes only) This should be seamless as I will be switching functionality regularly.
Compile to non-OS binary
I would like to compile D for the different supported architectures only without and OS, C lib, D lib, or GC code. For example, as a boot loader or even bios binary. In fact, it would be very helpful to have switches that disable the various "features" of D that I will not use rather than having to do any self compilation. Ultimately LDC and/or GDC will be required for optimized binaries with the same limitations. For testing purposes I would also like the ability to compile to the OS PE structure. For example import BIOS; void main() { BIOSOut("Hello World"); } will output
Re: DerelictGL3 glGenBuffers segmentation fault.
On Sunday, 24 December 2017 at 01:42:58 UTC, Mike Parker wrote: Need more info than this. Some code that reproduces the issue would be helpful. Also, what do you mean by "import my library"? I making a simple static library. For I can go through Opengl tutorials again. Need to refresh my memory. reproduce error code here. https://github.com/Windspar/Derelict-Testing Yes I know there other problems.
Re: Does LDC support profiling at all?
On Saturday, 23 December 2017 at 12:23:33 UTC, Johan Engelen wrote: On Friday, 22 December 2017 at 09:52:26 UTC, Chris Katko wrote: DMD can use -profile and -profile=gc. But I tried for HOURS to find the equivalent for LDC and came up with only profile-guided optimization--which I don't believe I want. Yet, if we can get PGO... where's the PROFILE itself it's using to make those decisions! :) Fine grained PGO profiling: -fprofile-instr-generate http://johanengelen.github.io/ldc/2016/07/15/Profile-Guided-Optimization-with-LDC.html Function entry/exit profiling: -finstrument-functions https://github.com/ldc-developers/ldc/issues/1839 https://www.youtube.com/watch?v=LNav5qvyK7I I suspect it is not too much effort to add DMD's -profile and -profile=gc to LDC, but noone has done it yet. Another thing that is relatively easy to add to LDC: https://llvm.org/docs/XRay.html -Johan Wow, thanks guys! I didn't realize I'd get so much information so quickly here on the forums. The documentation online for LDC is very sparse and confusing. After spending plenty of attempts, I went out of my way to install DMD just to get profiling because I couldn't figure it out with LDC. It would probably be really helpful to get a clear Wiki guide for this information LDC. I'll write it myself if necessary once I try your recommendations and test them out.
Re: GC in D and synadard library.
On Thursday, 21 December 2017 at 10:49:46 UTC, Dan Partelly wrote: I started to look into D very recently. I would like to know the following, if you guys are so nice to help me: 1. What is the performance of D's GC, what trade-offs where done in design , and if a in-deep primer on efficient usage and gotchas of the current implementation exists. 2. GC is never good enough. What are the current plans in this area for D. In general, please point me to the place where current work on D is done. 3. I need to be able to run with GC totally disabled sometimes. In the light of this: - are there any features of core language which depend on garbage collection ? (i.e unbound arrays, strings ..) - are there any features from standard library which depend on active garbage collection? - Please point me to a list where there is an exhaustive enumeration of which language features *and* library features requires GC active. Looking at standard library docs I did not seen markings which identify clearly and unequivocally what requires GC active and what not. 4. Is Andrei Alexandrescu's book from 2009 on D still actual, or the language evolution made it obsolete ? With thanks. I make hobby/proto-type games and I've been doing it for well-over a decade at this point. Starting learning D and trying games with Allegro 5 and D the same way I used C++. There's lots to learn. But so far it's a freaking DELIGHT to program in D compared to C++. It's so easy to reduce boilerplate, and extend code without huge swafts of boilerplate std::vector> template code. I'm intentionally ABUSING the GC so far by having every smoke particle (hundreds) with new ones allocate and and old ones deallocating every frame. I'm also developing on a tiny Chromebook with a Intel Celeron ~N2950 and only 2 GB of RAM (which Ubuntu eats most of). I'm still getting 115+ FPS drawing 600 alpha-blended "cloud" bitmaps each frame, plus the smoke trails, and allocations. There is a microstutter issue I'm diagnosing that may be related to GC. (After all, I AM intentionally abusing it so I can get a "feel" for it.) But it's not terrible. I plan to move to static pools for everything eventually but this is a viability study for D and the GC without going out of my way to disable/avoid the GC. Merely turning on Open Broadcast Studio to capture video of my game for explanations takes more CPU time than my game. So depending on what you want to design, I really second everyone's recommendation "don't worry about it until it's a problem." D is so adaptable that it's really easy to move away from the GC (assuming you write good code anyway). Now, to that previous point of "don't worry about it." I absolutely get the apprehension when someone tells you that. But yeah, it's not that bad. If you do "heavy lifting" stuff with static allocations, and leave the GC for making lambdas and stuff like that super-easy to write code, it's a good combination. As others have mentioned, you can even allocate memory that the GC has literally no idea about and will never collect. I definitely recommend trying D. The best way for you to know if it suits YOUR requirements is really... make a test app like I'm doing. Code the way you normally do and see if the GC affects you. Absolute worst case you can port your program to C++ pretty quickly.
Re: WARN on implicit super?
On Thursday, 21 December 2017 at 10:13:47 UTC, bauss wrote: On Thursday, 21 December 2017 at 06:47:25 UTC, Ali Çehreli wrote: [...] This is what I would believe __IS__ and __SHOULD__ be the default behavior too, because that's how it generally is in other languages. It doesn't make much sense to call a super constructer after and it's very rare cases that you need too. The only time you really call super constructors after is if the parameters are different. Ex. class Foo { int baz; int boo; this() { ... } this(int baz, int boo) { ... } } class Bar : Foo { this() { int baz =getBazFromSomewhere(); int boo = getBooFromSomewhere(); super(baz, boo); } } In that case it makes sense to call super() after, but you rarely end up in cases like that and thus you should generally be able to omit the call. If super() is ever called explicit after (if no call to a super constructor has been done.) then I can only imagine A LOT of code will break, because it's a general concept and known behavior from most languages that base/super constructors are called before. I think during many late night debugging, I had TWO bugs and confused super call-order and wrote that comment. What I think happened was, super() was called correctly, but, the chain of classes was calling this()/super() constructors and DIDN'T call this(var, var)/super(var,var) constructors that I needed. So AFAIK, I'd call this a closed problem / mistaken understanding. Thanks for your prompt replies and help. Sorry if I wasted your time.
Re: Why does calling a struct constructor generate linker errors when using Better C?
On Sunday, 24 December 2017 at 01:29:56 UTC, rikki cattermole wrote: Although maybe you ought to start out with regular D. -betterC is really there for those who want D but can't have druntime. They should already know D pretty well. I'm using -betterC on purpose, doing bare-metal development. Had to learn a new language anyway, and I had been following D for 8 years or so. I started out with a stubbed object.d but that turned out to be too hard, so switched to -betterC by recommendation of some people on IRC.
Re: DerelictGL3 glGenBuffers segmentation fault.
On Sunday, 24 December 2017 at 00:58:25 UTC, Kevin wrote: When I import my library into my program. glGenBuffers segmentation fault. When I copy VertexBuffer into main code. It works fine. Why am I getting segmentation fault from library ? Need more info than this. Some code that reproduces the issue would be helpful. Also, what do you mean by "import my library"?
Re: Why does calling a struct constructor generate linker errors when using Better C?
On 24/12/2017 1:25 AM, Stijn wrote: On Sunday, 24 December 2017 at 01:21:53 UTC, rikki cattermole wrote: On 24/12/2017 1:20 AM, Stijn wrote: [...] new uses GC. It has nothing to do with structs. Oh I see, simply removing 'new' solves the problem. I've a C# background, so I hadn't thought of doing that. Thanks! Yeah new = memory allocation. Although maybe you ought to start out with regular D. -betterC is really there for those who want D but can't have druntime. They should already know D pretty well.
Re: Why does calling a struct constructor generate linker errors when using Better C?
On Sunday, 24 December 2017 at 01:21:53 UTC, rikki cattermole wrote: On 24/12/2017 1:20 AM, Stijn wrote: [...] new uses GC. It has nothing to do with structs. Oh I see, simply removing 'new' solves the problem. I've a C# background, so I hadn't thought of doing that. Thanks!
Why does calling a struct constructor generate linker errors when using Better C?
https://dlang.org/spec/betterc.html doesn't mention struct constructors not working, but I'm getting linker errors when trying to call a struct constructor. Consider the following program betterc.d struct foo { } extern(C) void main() { auto bar = new foo(); } Compile with: dmd -c -m32 betterc.d -betterC Link with: gcc -m32 betterc.o -Wl,--build-id=none -nostdlib -o "betterc.bin" Linker output: betterc.o: In function `main': betterc.d:(.text.main[main]+0xa): undefined reference to `_d_newitemT' betterc.o:(.data._D22TypeInfo_S7betterc3foo6__initZ+0x0): undefined reference to `_D15TypeInfo_Struct6__vtblZ' collect2: error: ld returned 1 exit status Is there a mistake in my code, or is the documentation lacking?
Re: Why does calling a struct constructor generate linker errors when using Better C?
On 24/12/2017 1:20 AM, Stijn wrote: https://dlang.org/spec/betterc.html doesn't mention struct constructors not working, but I'm getting linker errors when trying to call a struct constructor. Consider the following program betterc.d struct foo { } extern(C) void main() { auto bar = new foo(); } Compile with: dmd -c -m32 betterc.d -betterC Link with: gcc -m32 betterc.o -Wl,--build-id=none -nostdlib -o "betterc.bin" Linker output: betterc.o: In function `main': betterc.d:(.text.main[main]+0xa): undefined reference to `_d_newitemT' betterc.o:(.data._D22TypeInfo_S7betterc3foo6__initZ+0x0): undefined reference to `_D15TypeInfo_Struct6__vtblZ' collect2: error: ld returned 1 exit status Is there a mistake in my code, or is the documentation lacking? new uses GC. It has nothing to do with structs.
DerelictGL3 glGenBuffers segmentation fault.
I'm working a library with DerelictGL3. using branch 2.0 import derelict.opengl; import std.stdio : writeln; struct VertexBuffer { GLuint vbo; GLsizei count; this(GLsizei n) { writeln("creating vbo"); glGenBuffers(n, &vbo); writeln("created vbo"); count = n; writeln("exiting vbo"); } // more code } When I import my library into my program. glGenBuffers segmentation fault. When I copy VertexBuffer into main code. It works fine. Why am I getting segmentation fault from library ?
indexing stuff during compile time
I am trying to build a string->int dictionary at compile time. The ints are unique and must not be greater than the number of unique strings. So, they are sequential for each string that is not yet indexed. Example: size_t idx1 = nameToIndex!"blah"; // 0 size_t idx2 = nameToIndex!"blah2"; // 1 size_t idx3 = nameToIndex!"blah"; // 0 size_t idx4 = nameToIndex!"blah3"; // 2 So, you need to keep a static nextFreeIndex somewhere, but the problem is that you can't use static vars during compile time. Any ideas how to work around this? FWISW, here's some code. I am actually trying to map a combination of types to an index: struct A {} struct B {} void test() { writeln("a : " ~ groupIndex!(A).tostr); // 0 writeln("b : " ~ groupIndex!(B).tostr); // 1 writeln("ab : " ~ groupIndex!(A,B).tostr); // 2 } auto groupIndex(Ts...)() { enum n = groupName!Ts(); enum idx = nameToIdx(n); return idx; } // get or associate new index with the name size_t nameToIdx(string n) { static size_t[string] name2idx; static size_t s_nextIdx = 0; size_t* idx = n in name2idx; if (!idx) { name2idx[n] = s_nextIdx++; return s_nextIdx-1; } else return *idx; } // different attempt, but same problem: //size_t nameToIdx(string n)() { // mixin("static struct _"~n ~ "{ static int id;}"); // return mixin("_"~n~".id"); //} string groupName(Ts...)() { string n; foreach(t; Ts) { n = n ~ t.stringof; } return n; } string tostr(T)(T t) { import std.conv; return to!string(t); }
Re: What does scope do as storage class?
On Saturday, 23 December 2017 at 21:20:13 UTC, Jonathan M Davis wrote: On Saturday, December 23, 2017 21:05:25 Marc via Digitalmars-d-learn wrote: for example: scope struct S { int x; } What does scope do here? Absolutely nothing. https://stackoverflow.com/questions/47240714/d-pure-classes-and-structs - Jonathan M Davis There's one special case, though, with scope in classes - scope will force user to allocate class as a scope: ``` scope class X { int x; } void main() { auto instance = new X; // ERROR must be scope instance = new X; } ```
Re: GC in D and synadard library.
On Thursday, December 21, 2017 12:00:17 Mike Franklin via Digitalmars-d- learn wrote: > I'm not a big user of the standard library, but I believe most > features of the standard library require the GC. Actually, relatively little in Phobos explicitly uses the GC. There are some things that definitely do (e.g. std.array.array), but the vast majority is range-based and doesn't explicitly allocate anything. The main problem is that lambdas often result in the compiler deciding that a closure needs to be allocated to ensure that the code is @safe with regards to the stack variables that the lambda accesses. So, for a lot of stuff, if you just use stuff like static nested functions or functors instead of lambdas, you won't get any GC allocations, but there are certainly places where the library allocates where it shouldn't (e.g. one range-based function calls another with a lambda that results in an allocation), and more work needs to be done to ensure that all of the stuff like that is caught and fixed. So, if you want to avoid the GC, you do have to be careful with Phobos, and Phobos does need some improvements to remove inadvertent uses fo the GC, but relatively little in Phobs allocates memory. Most problems that someone is likely to have with the GC stem from their own code, not the standard library. And actually, idiomatic D does tend to reduce how much your typical program allocates (e.g. lots of structs on the stack and preferring lazy ranges to arrays), which means that the GC typically has a far lower impact than many people assume that it will - though if someone is writing their code like it's Java and uses lots of classes and puts most stuff on the heap, then they're bound to have performance problems. - Jonathan M Davis
Re: What does scope do as storage class?
On Saturday, December 23, 2017 21:05:25 Marc via Digitalmars-d-learn wrote: > for example: > > scope struct S { >int x; > } > > What does scope do here? Absolutely nothing. https://stackoverflow.com/questions/47240714/d-pure-classes-and-structs - Jonathan M Davis
What does scope do as storage class?
for example: scope struct S { int x; } What does scope do here?
Re: Does LDC support profiling at all?
On Saturday, 23 December 2017 at 12:23:33 UTC, Johan Engelen wrote: Fine grained PGO profiling: -fprofile-instr-generate http://johanengelen.github.io/ldc/2016/07/15/Profile-Guided-Optimization-with-LDC.html Function entry/exit profiling: -finstrument-functions https://github.com/ldc-developers/ldc/issues/1839 https://www.youtube.com/watch?v=LNav5qvyK7I I suspect it is not too much effort to add DMD's -profile and -profile=gc to LDC, but noone has done it yet. Another thing that is relatively easy to add to LDC: https://llvm.org/docs/XRay.html Apart from profiling based on compiler instrumentation, don't forget that LDC uses the standard object file formats/runtime libraries for the various platforms, so all the usual profiling tools like perf, VTune, Valgrind, etc. work just fine. I would usually start with one of the latter for general-purpose optimization work. — David
DUB describe error in Eclipse
Eclipse: Version: Neon.3 Release (4.6.3) Platform: Ubuntu 16.04 I have a running version of dub and dmd that works from the command line. But does not work from Eclipse (DDT). When i CTRL+Click on a function or module it should take me to the source, instead if gives the following error: Unresolved dub manifest: Failed to invoke the compiler dmd to determine the build platform:
Re: Finding equivalent of C++ feature in D documentation.
On Saturday, 23 December 2017 at 15:58:27 UTC, Seb wrote: On Saturday, 23 December 2017 at 15:45:33 UTC, Mike Franklin wrote: On Saturday, 23 December 2017 at 15:04:30 UTC, kerdemdemir wrote: Is there any better way for me to search C/C++ equivalent features? As a humble suggestion would it make sense to make a table with feature names and corresponding name of the same feature in other languages ? Try this: https://wiki.dlang.org/Programming_in_D_for_C%2B%2B_Programmers ... and potentially this: https://wiki.dlang.org/Coming_From Those resources are community maintained. When I was first learning D, if I encountered a problem and struggled to a solution, I would make an attempt to documented it on the D wiki to try and save others from having to go through the same difficulty. I encourage you to do the same. Mike There are these two pages: https://dlang.org/ctod.html https://dlang.org/cpptod.html Thanks guys both pages are good. @Mike I really want to add this case about M.I.L syntax in to wiki page. But since I am not a D pro; I am shy and also I am not sure if I have the permission to modify this page. Do you suggest me to try adding this spesific to the wiki page?
Re: Finding equivalent of C++ feature in D documentation.
On Saturday, 23 December 2017 at 15:45:33 UTC, Mike Franklin wrote: On Saturday, 23 December 2017 at 15:04:30 UTC, kerdemdemir wrote: Is there any better way for me to search C/C++ equivalent features? As a humble suggestion would it make sense to make a table with feature names and corresponding name of the same feature in other languages ? Try this: https://wiki.dlang.org/Programming_in_D_for_C%2B%2B_Programmers ... and potentially this: https://wiki.dlang.org/Coming_From Those resources are community maintained. When I was first learning D, if I encountered a problem and struggled to a solution, I would make an attempt to documented it on the D wiki to try and save others from having to go through the same difficulty. I encourage you to do the same. Mike There are these two pages: https://dlang.org/ctod.html https://dlang.org/cpptod.html
Re: Finding equivalent of C++ feature in D documentation.
On Saturday, 23 December 2017 at 15:04:30 UTC, kerdemdemir wrote: Is there any better way for me to search C/C++ equivalent features? As a humble suggestion would it make sense to make a table with feature names and corresponding name of the same feature in other languages ? Try this: https://wiki.dlang.org/Programming_in_D_for_C%2B%2B_Programmers ... and potentially this: https://wiki.dlang.org/Coming_From Those resources are community maintained. When I was first learning D, if I encountered a problem and struggled to a solution, I would make an attempt to documented it on the D wiki to try and save others from having to go through the same difficulty. I encourage you to do the same. Mike
Finding equivalent of C++ feature in D documentation.
I needed to find equivalent of member initialization list in D. After searching ~10 minutes I found D has very elegant solution (https://dlang.org/spec/class.html#field-init) after reading through whole constructor page. My question is not technical this time I have my solution. But I think when I google "Member inilization in D" I am expecting to be directed to correct documentation. This unfortunately happens a lot to me. And this minutes sum into hours and inefficiency. Is there any better way for me to search C/C++ equivalent features? As a humble suggestion would it make sense to make a table with feature names and corresponding name of the same feature in other languages ? Erdem
Re: Compiler gets confused with ambiguity when `int` matches both `real` and `float`.
On Saturday, 23 December 2017 at 07:25:34 UTC, IM wrote: The following expression: import std.math : sqrt; sqrt(400); produces the following compiler error: std.math.sqrt called with argument types (int) matches both: /usr/include/dmd/phobos/std/math.d(1592,7): std.math.sqrt(float x) and: /usr/include/dmd/phobos/std/math.d(1598,6): std.math.sqrt(real x) Shouldn't it just pick one according to some defined rules? C++ complains the same between float and double. Just put 400.0f or whatever precision you want to use. I think it's better that it doesn't just pick one.
Re: One liner for creating an array filled by a factory method
On Saturday, 23 December 2017 at 08:57:18 UTC, kerdemdemir wrote: On Friday, 22 December 2017 at 23:33:55 UTC, Mengu wrote: On Thursday, 21 December 2017 at 21:11:58 UTC, Steven Schveighoffer wrote: On 12/21/17 4:00 PM, kerdemdemir wrote: I have a case like : http://rextester.com/NFS28102 I have a factory method, I am creating some instances given some enums. My question is about : void PushIntoVector( BaseEnum[] baseEnumList ) { Base[] baseList; foreach ( tempEnum; baseEnumList ) { baseList ~= Factory(tempEnum); } } I don't want to use "foreach" loop. Is there any cool std function that I can call ? Something like baseEnumList.CoolStdFunc!( a=> Factory(a) )(baseList); https://dlang.org/phobos/std_algorithm_iteration.html#map -Steve so basically it becomes: Base[] baseList = baseEnumList.map!(el => Factory(el)); there's also a parallel version of map [0] if you ever need to map the list concurrently. [0] https://dlang.org/phobos/std_parallelism.html#.TaskPool.map Yeah that was very easy and I used to use map for this purposed a lot already. I don't know why I get confused. Thanks guys for correction. I began to think like map could transform but it can't create vector of elements and this confused me. it totally depends on the type of resulting element. if you expect Base[], then your map should transform your range / array elements into a Base. import std.range, std.algorithm; auto a = iota(1, 10); int[] b = a.map!(el => el + 1).array; int[][] c = a.map!(el => [el, el + 1]).array; writeln(b); writeln(c);
Re: Does LDC support profiling at all?
On Friday, 22 December 2017 at 09:52:26 UTC, Chris Katko wrote: DMD can use -profile and -profile=gc. But I tried for HOURS to find the equivalent for LDC and came up with only profile-guided optimization--which I don't believe I want. Yet, if we can get PGO... where's the PROFILE itself it's using to make those decisions! :) Fine grained PGO profiling: -fprofile-instr-generate http://johanengelen.github.io/ldc/2016/07/15/Profile-Guided-Optimization-with-LDC.html Function entry/exit profiling: -finstrument-functions https://github.com/ldc-developers/ldc/issues/1839 https://www.youtube.com/watch?v=LNav5qvyK7I I suspect it is not too much effort to add DMD's -profile and -profile=gc to LDC, but noone has done it yet. Another thing that is relatively easy to add to LDC: https://llvm.org/docs/XRay.html -Johan
Re: [DMD or LDC] Is it possible to get the GC to print to stdout when it collects?
On 23/12/2017 11:06 AM, Chris Katko wrote: I'm having a strange stuttering issue in my game prototype. I use GC allocations wildly for the heck of it at the moment--with eventual plans to remove them. However, I'm not positive it's the GC that's the problem, and if so, I want to know exact lengths of time and frequency. Currently, the game will freeze for up to even half a second or more (but pretty rarely of 15+ seconds apart or more) but strangely... I'm using stopwatch's to track the logic and drawing code's elapsed times and ... those stopwatches don't appear to show the frozen time. Maybe my time code is incorrect somewhere but I need to be sure. The hallmarks of GC are there because it "seems" to occur more often / worse when I'm low on RAM. In LDC2, I saw import/core/memory.d -> gc.collect() which calls gc_collect (a C function) However, adding a printf in there doesn't appear to print, so I'm guessing that gc.collect is only for users and not actually called by any internal lib functions? So my next thought is, to get a full source distribution, and recompile DMD or LDC2 from source after finding that C source file and adding a printf in there. I doubt a single printf (or some static string equivalent without formatting overhead) would take that much time compared to a complete garbage collection so I don't think it would skew the results enough to useless. The big thing to check here is if these "freezes" are directly related to garbage collections, or some other oddity. This isn't related to LDC. Its just using extern(C) for its linkage abilities. https://github.com/dlang/druntime/blob/master/src/gc/proxy.d#L90
[DMD or LDC] Is it possible to get the GC to print to stdout when it collects?
I'm having a strange stuttering issue in my game prototype. I use GC allocations wildly for the heck of it at the moment--with eventual plans to remove them. However, I'm not positive it's the GC that's the problem, and if so, I want to know exact lengths of time and frequency. Currently, the game will freeze for up to even half a second or more (but pretty rarely of 15+ seconds apart or more) but strangely... I'm using stopwatch's to track the logic and drawing code's elapsed times and ... those stopwatches don't appear to show the frozen time. Maybe my time code is incorrect somewhere but I need to be sure. The hallmarks of GC are there because it "seems" to occur more often / worse when I'm low on RAM. In LDC2, I saw import/core/memory.d -> gc.collect() which calls gc_collect (a C function) However, adding a printf in there doesn't appear to print, so I'm guessing that gc.collect is only for users and not actually called by any internal lib functions? So my next thought is, to get a full source distribution, and recompile DMD or LDC2 from source after finding that C source file and adding a printf in there. I doubt a single printf (or some static string equivalent without formatting overhead) would take that much time compared to a complete garbage collection so I don't think it would skew the results enough to useless. The big thing to check here is if these "freezes" are directly related to garbage collections, or some other oddity.
Re: One liner for creating an array filled by a factory method
On Friday, 22 December 2017 at 23:33:55 UTC, Mengu wrote: On Thursday, 21 December 2017 at 21:11:58 UTC, Steven Schveighoffer wrote: On 12/21/17 4:00 PM, kerdemdemir wrote: I have a case like : http://rextester.com/NFS28102 I have a factory method, I am creating some instances given some enums. My question is about : void PushIntoVector( BaseEnum[] baseEnumList ) { Base[] baseList; foreach ( tempEnum; baseEnumList ) { baseList ~= Factory(tempEnum); } } I don't want to use "foreach" loop. Is there any cool std function that I can call ? Something like baseEnumList.CoolStdFunc!( a=> Factory(a) )(baseList); https://dlang.org/phobos/std_algorithm_iteration.html#map -Steve so basically it becomes: Base[] baseList = baseEnumList.map!(el => Factory(el)); there's also a parallel version of map [0] if you ever need to map the list concurrently. [0] https://dlang.org/phobos/std_parallelism.html#.TaskPool.map Yeah that was very easy and I used to use map for this purposed a lot already. I don't know why I get confused. Thanks guys for correction. I began to think like map could transform but it can't create vector of elements and this confused me.