Re: GC configuration docs
On 05.01.2016 01:39, Dan Olson wrote: I haven't played with any of the new GC configuration options introduced in 2.067, but now need to. An application on watchOS currently has about 30 MB of RAM. Is there any more documentation than the web page https://dlang.org/spec/garbage.html or should I just browse druntime code? I don't think there is more than that. Also pointers (pun maybe) on finding who has the references keeping memory from being collected. There is a "leak detector" in the GC compiled into it the with -debug=LOGGING, but I guess noone has been using it the last couple of years (and it seems to me it doesn't really do anything more than printing allocations). I used -debug=PRINTF, -debug=PRINTF_COLLECT and -debug=PRINTF_TO_FILE in the past and grepped the resulting gcx.log. You might want to uncomment some printf in the mark function, too.
Re: question about the implementation of Variant
Thank you, Jonathan. Now I understand. On Monday, 4 January 2016 at 17:34:47 UTC, Kapps wrote: union { ubyte[size] store; // conservatively mark the region as pointers static if (size >= (void*).sizeof) void*[size / (void*).sizeof] p; } Interesting to know the way to make GC detect the presence of the potential pointer. Regards, aki.
Re: Get superclasses at compile time
On 05/01/16 5:50 PM, Straivers wrote: On Tuesday, 5 January 2016 at 04:41:45 UTC, Rikki Cattermole wrote: On 05/01/16 5:37 PM, Straivers wrote: Hello, I'm working on an event system, and I want to be able to check if an event is a subclass of another event. How might I go about this? In essence, I'm looking to compress this: static if (E == UserInputEvent || E == MouseEvent || E == MouseButtonEvent || E == MouseReleasedEvent) { //MouseEvent => MouseButtonEvent => MouseReleasedEvent mreListeners[mrePtr] = listener; mrePtr++; } into something like this: static if (isSuperclassOf!(MouseReleasedEvent, E)) { mreListeners[mrePtr] = listener; mrePtr++; } Thank you for your time. -S is(E : UserInputEvent) Okay, maybe I didn't write enough. I have multiple subtypes like: static if (E == UserInputEvent || E == MouseEvent || E == MouseMovementEvent) { //MouseMovementEvent is a subclass of MouseEvent mmeListeners[mmePtr] = listener; mmePtr++; } static if (E == UserInputEvent || E == MouseEvent || E == MouseButtonEvent || E == MouseReleasedEvent) { //MouseEvent => MouseButtonEvent => MouseReleasedEvent mreListeners[mrePtr] = listener; mrePtr++; } static if (E == UserInputEvent || E == MouseEvent || E == MouseButtonEvent || E == MousePressedEvent) { //MouseEvent => MouseButtonEvent => MousePressedEvent mpeListeners[mpePtr] = listener; mpePtr++; } and I want to differentiate between them so that a UserInputEvent will cause all three blocks to be compiled, but a MouseMovementEvent will only cause the first block to be compiled. Sorry about that. static if (is(E : UserInputEvent) || is(E : MouseEvent) || is(E : MouseButtonEvent) || is(E : MousePressedEvent)) { // }
Re: Get superclasses at compile time
On Tuesday, 5 January 2016 at 04:41:45 UTC, Rikki Cattermole wrote: On 05/01/16 5:37 PM, Straivers wrote: Hello, I'm working on an event system, and I want to be able to check if an event is a subclass of another event. How might I go about this? In essence, I'm looking to compress this: static if (E == UserInputEvent || E == MouseEvent || E == MouseButtonEvent || E == MouseReleasedEvent) { //MouseEvent => MouseButtonEvent => MouseReleasedEvent mreListeners[mrePtr] = listener; mrePtr++; } into something like this: static if (isSuperclassOf!(MouseReleasedEvent, E)) { mreListeners[mrePtr] = listener; mrePtr++; } Thank you for your time. -S is(E : UserInputEvent) Okay, maybe I didn't write enough. I have multiple subtypes like: static if (E == UserInputEvent || E == MouseEvent || E == MouseMovementEvent) { //MouseMovementEvent is a subclass of MouseEvent mmeListeners[mmePtr] = listener; mmePtr++; } static if (E == UserInputEvent || E == MouseEvent || E == MouseButtonEvent || E == MouseReleasedEvent) { //MouseEvent => MouseButtonEvent => MouseReleasedEvent mreListeners[mrePtr] = listener; mrePtr++; } static if (E == UserInputEvent || E == MouseEvent || E == MouseButtonEvent || E == MousePressedEvent) { //MouseEvent => MouseButtonEvent => MousePressedEvent mpeListeners[mpePtr] = listener; mpePtr++; } and I want to differentiate between them so that a UserInputEvent will cause all three blocks to be compiled, but a MouseMovementEvent will only cause the first block to be compiled. Sorry about that.
Re: Get superclasses at compile time
On 05/01/16 5:37 PM, Straivers wrote: Hello, I'm working on an event system, and I want to be able to check if an event is a subclass of another event. How might I go about this? In essence, I'm looking to compress this: static if (E == UserInputEvent || E == MouseEvent || E == MouseButtonEvent || E == MouseReleasedEvent) { //MouseEvent => MouseButtonEvent => MouseReleasedEvent mreListeners[mrePtr] = listener; mrePtr++; } into something like this: static if (isSuperclassOf!(MouseReleasedEvent, E)) { mreListeners[mrePtr] = listener; mrePtr++; } Thank you for your time. -S is(E : UserInputEvent)
Get superclasses at compile time
Hello, I'm working on an event system, and I want to be able to check if an event is a subclass of another event. How might I go about this? In essence, I'm looking to compress this: static if (E == UserInputEvent || E == MouseEvent || E == MouseButtonEvent || E == MouseReleasedEvent) { //MouseEvent => MouseButtonEvent => MouseReleasedEvent mreListeners[mrePtr] = listener; mrePtr++; } into something like this: static if (isSuperclassOf!(MouseReleasedEvent, E)) { mreListeners[mrePtr] = listener; mrePtr++; } Thank you for your time. -S
Re: std.experimental.logger
On Tuesday, 5 January 2016 at 02:59:04 UTC, sanjayss wrote: On Tuesday, 5 January 2016 at 02:49:01 UTC, Mike wrote: [...] Thanks, that works. But the docs are confusing -- it gives the impression that "sharedLog" is something associated with the default logger -- so I would expect the above to work with just the plain log() call to invoke the default logger. But it seems like I am just creating a new logger and using that by saying "sharedLog.log()". From the doc: The default Logger will by default log to stderr and has a default LogLevel of LogLevel.all. The default Logger can be accessed by using the property called sharedLog. This property a reference to the current default Logger. This reference can be used to assign a new default Logger. sharedLog = new FileLogger("New_Default_Log_File.log"); You are right, according to the docs your example should've worked just fine. Tried it myself on DMD 2.069.2 and it doesn't work either. You should raise an issue on github.
Re: std.experimental.logger
On Tuesday, 5 January 2016 at 02:49:01 UTC, Mike wrote: On Tuesday, 5 January 2016 at 02:44:48 UTC, sanjayss wrote: I'm doing the following: import std.experimental.logger; int main(string[] args) { sharedLog = new FileLogger("logfile.log"); log("Test log 1"); log("Test log 2"); log("Test log 3"); } and I expected the logs to be seen in the logfile.log, but it seems like my reading of the docs on this is incorrect and the logfile.log is not populated at all (though it is created). What am I missing or using incorrectly? Basically I am trying to have the default logger log to a file instead of stderr. (I am on a Mac (OS-X 10.11.1, 64 bit) and using DMD 2.069.2) You need to log with sharedLog: sharedLog.log("Test log 1"); sharedLog.log("Test log 2"); sharedLog.log("Test log 3"); Thanks, that works. But the docs are confusing -- it gives the impression that "sharedLog" is something associated with the default logger -- so I would expect the above to work with just the plain log() call to invoke the default logger. But it seems like I am just creating a new logger and using that by saying "sharedLog.log()". From the doc: The default Logger will by default log to stderr and has a default LogLevel of LogLevel.all. The default Logger can be accessed by using the property called sharedLog. This property a reference to the current default Logger. This reference can be used to assign a new default Logger. sharedLog = new FileLogger("New_Default_Log_File.log");
Re: std.experimental.logger
On Tuesday, 5 January 2016 at 02:44:48 UTC, sanjayss wrote: I'm doing the following: import std.experimental.logger; int main(string[] args) { sharedLog = new FileLogger("logfile.log"); log("Test log 1"); log("Test log 2"); log("Test log 3"); } and I expected the logs to be seen in the logfile.log, but it seems like my reading of the docs on this is incorrect and the logfile.log is not populated at all (though it is created). What am I missing or using incorrectly? Basically I am trying to have the default logger log to a file instead of stderr. (I am on a Mac (OS-X 10.11.1, 64 bit) and using DMD 2.069.2) You need to log with sharedLog: sharedLog.log("Test log 1"); sharedLog.log("Test log 2"); sharedLog.log("Test log 3");
std.experimental.logger
I'm doing the following: import std.experimental.logger; int main(string[] args) { sharedLog = new FileLogger("logfile.log"); log("Test log 1"); log("Test log 2"); log("Test log 3"); } and I expected the logs to be seen in the logfile.log, but it seems like my reading of the docs on this is incorrect and the logfile.log is not populated at all (though it is created). What am I missing or using incorrectly? Basically I am trying to have the default logger log to a file instead of stderr. (I am on a Mac (OS-X 10.11.1, 64 bit) and using DMD 2.069.2)
GC configuration docs
I haven't played with any of the new GC configuration options introduced in 2.067, but now need to. An application on watchOS currently has about 30 MB of RAM. Is there any more documentation than the web page https://dlang.org/spec/garbage.html or should I just browse druntime code? Also pointers (pun maybe) on finding who has the references keeping memory from being collected. -- Dan
Re: GTKD Cairo get pixel color
On Friday, 1 January 2016 at 22:00:04 UTC, TheDGuy wrote: On Friday, 1 January 2016 at 19:32:40 UTC, Basile B. wrote: On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. wrote: On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote: Hello, is there any way to get the pixel color of a single pixel by x and y coordinates of a context? render to a png back buffer. see cairo_image_surface_create_for_data then you'll be able to access the data and, at the same time, to blit your buffer to screen. Actually I was thinking to a user defined buffer type: struct SurfaceBuffer { void* data; // used as param to create the surface Rgba[] opIndex(size_t index); Rgba[][] scanline(); } that you would pass as data in cairo_image_surface_create_for_data(). But gtk certainly has pitcure classes with the typical scanline method and that you could use in cairo_image_surface_create_for_data. Ahm, i am not quite sure if you and [Mike Wey] talk about the same thing. And i posted the error message in my last post when i try to call "cairo_image_surface_create_for_data". I still don't know where i am able to call the function? I've not followed the conversation since last time, but you can have a look at this: https://github.com/BBasile/kheops/blob/master/src/kheops/bitmap.d#L143 this is how I do with Cairo only (even x11 is not implied since it's just a bitmap). Then I can access pixels (for example to make shadows or blurs etc.) and do vectorial drawings as well with a context for the bitmap surface.
What are the useful inout free functions?
Can someone produce a _useful_ free function that uses inout? There are useful getters using inout. There are useless free functions using inout like http://dpaste.dzfl.pl/d038012308ed
Re: What are the useful inout free functions?
On Monday, 4 January 2016 at 23:15:22 UTC, Guillaume Piolat wrote: Can someone produce a _useful_ free function that uses inout? There are useful getters using inout. There are useless free functions using inout like http://dpaste.dzfl.pl/d038012308ed Adam D. Ruppe answered this on IRC: inout(char)[] chomp(inout(char)[] str) { return if(str.length && str[$-1] == '\n') str[0 .. $-1] : str; }
Re: Threading to prevent GUI Freeze
On 01/04/2016 06:31 AM, TheDGuy wrote: > I tried it with "std.concurrency" like this: > > bool drawCallback(Scoped!Context cr, Widget widget){ > writeln("init"); > spawn(&render, cr, widget); The first parameter to render() is Scoped!Context but render() takes a Context: > void render(Context cr, Widget widget){ Unless there is implicit conversion from Scoped!Context to Context, it won't work. Perhaps you need to call an accessor like the following? spawn(&render, cr.some_accessor(), widget); Ali
Re: GTKD Cairo get pixel color
On Monday, 4 January 2016 at 21:42:16 UTC, Mike Wey wrote: On 01/04/2016 09:13 PM, TheDGuy wrote: [...] I don't have any issues with either getPixelsWithLength and savev. for the savev call there is an missing \ just before test.jpg, but that might be a copy and paste error? For the options that are available for savev the documentation of GDK-PixBuff lists the few available options. https://developer.gnome.org/gdk-pixbuf/unstable/gdk-pixbuf-File-saving.html#gdk-pixbuf-save Although i'm on Linux so that might make an difference. Ups, that was my fault, sry :( But how do i get now the color for each pixel out of the ubyte[]?
Re: GTKD Cairo get pixel color
On 01/04/2016 09:13 PM, TheDGuy wrote: On Monday, 4 January 2016 at 19:27:48 UTC, Mike Wey wrote: I think you are looking for something like this. Context.getTarget will get you the surface the Context is drawing to, this most likely isn't a ImageSurface. So you will need to create an pixbuf from the returned surface, with the Pixbuf you can then get the raw pixel data using getPixelsWithLength(). ``` import gdk.Pixbuf; bool drawCallback(Scoped!Context cr, Widget widget) { GtkAllocation size; Pixbuf surafce; getAllocation(size); //Draw something; surface = getFromSurface(cr.getTarget(), 0, 0, size.width, size.height); ubyte[] data = cast(ubyte[])surface.getPixelsWithLength(); //Do somthing with data. return true; } ``` getPixelsWithLength has the wrong return type, which will probably be fixed some time. Thank you very much! But surface.getPixelsWithLength() only gives me an array with 16 fields (with a 256x256 DrawingArea)? I also tried to save the Pixbuf with: string[] options = ["quality"]; string[] opval = ["100"]; surface.savev("C:\\Users\\Standardbenutzer\\Desktop\test.jpeg", "jpeg", options, opval); but i found absolutely NOTHING about the options or the option values i have to set, therefore i get an invalid argument exception :( I don't have any issues with either getPixelsWithLength and savev. for the savev call there is an missing \ just before test.jpg, but that might be a copy and paste error? For the options that are available for savev the documentation of GDK-PixBuff lists the few available options. https://developer.gnome.org/gdk-pixbuf/unstable/gdk-pixbuf-File-saving.html#gdk-pixbuf-save Although i'm on Linux so that might make an difference. -- Mike Wey
Re: Are there any D scripting engines for use with D?
On Monday, 4 January 2016 at 19:25:18 UTC, yawniek wrote: On Monday, 4 January 2016 at 19:04:48 UTC, Max Klyga wrote: On 2016-01-04 18:40:03 +, Jason Jeffory said: The fastest one would probably be Lua - http://code.dlang.org/search?q=lua But there are other options: Python - http://code.dlang.org/packages/pyd Javascript - http://code.dlang.org/search?q=javascript and http://pointersgonewild.com/higgs/ Croc (previously miniD, a scripting language implemented in D) - http://jfbillingsley.com/croc/ there is also http://code.dlang.org/packages/d_mruby mruby is really nice. but i agree, a more native language that would not need to push data via a stack but instead had direct access to strings or defined objects would be something really helpful. All these are ok, luaD being the preferred choice(croc looks nice but haven't spent much time with it). I'd prefer a D based scripting engine. I suppose one could simply compile the code for each change, but seems like it would be a mess. The ability to debug and provide real time changes would be great.
Re: GTKD Cairo get pixel color
On Monday, 4 January 2016 at 19:27:48 UTC, Mike Wey wrote: I think you are looking for something like this. Context.getTarget will get you the surface the Context is drawing to, this most likely isn't a ImageSurface. So you will need to create an pixbuf from the returned surface, with the Pixbuf you can then get the raw pixel data using getPixelsWithLength(). ``` import gdk.Pixbuf; bool drawCallback(Scoped!Context cr, Widget widget) { GtkAllocation size; Pixbuf surafce; getAllocation(size); //Draw something; surface = getFromSurface(cr.getTarget(), 0, 0, size.width, size.height); ubyte[] data = cast(ubyte[])surface.getPixelsWithLength(); //Do somthing with data. return true; } ``` getPixelsWithLength has the wrong return type, which will probably be fixed some time. Thank you very much! But surface.getPixelsWithLength() only gives me an array with 16 fields (with a 256x256 DrawingArea)? I also tried to save the Pixbuf with: string[] options = ["quality"]; string[] opval = ["100"]; surface.savev("C:\\Users\\Standardbenutzer\\Desktop\test.jpeg", "jpeg", options, opval); but i found absolutely NOTHING about the options or the option values i have to set, therefore i get an invalid argument exception :(
Re: Are there any D scripting engines for use with D?
On Monday, 4 January 2016 at 19:04:48 UTC, Max Klyga wrote: On 2016-01-04 18:40:03 +, Jason Jeffory said: The fastest one would probably be Lua - http://code.dlang.org/search?q=lua But there are other options: Python - http://code.dlang.org/packages/pyd Javascript - http://code.dlang.org/search?q=javascript and http://pointersgonewild.com/higgs/ Croc (previously miniD, a scripting language implemented in D) - http://jfbillingsley.com/croc/ there is also http://code.dlang.org/packages/d_mruby mruby is really nice. but i agree, a more native language that would not need to push data via a stack but instead had direct access to strings or defined objects would be something really helpful.
Re: GTKD Cairo get pixel color
I think you are looking for something like this. Context.getTarget will get you the surface the Context is drawing to, this most likely isn't a ImageSurface. So you will need to create an pixbuf from the returned surface, with the Pixbuf you can then get the raw pixel data using getPixelsWithLength(). ``` import gdk.Pixbuf; bool drawCallback(Scoped!Context cr, Widget widget) { GtkAllocation size; Pixbuf surafce; getAllocation(size); //Draw something; surface = getFromSurface(cr.getTarget(), 0, 0, size.width, size.height); ubyte[] data = cast(ubyte[])surface.getPixelsWithLength(); //Do somthing with data. return true; } ``` getPixelsWithLength has the wrong return type, which will probably be fixed some time. -- Mike Wey
Re: Are there any D scripting engines for use with D?
On Monday, 4 January 2016 at 18:40:03 UTC, Jason Jeffory wrote: We have many scripting engines available for use in D more or less(lua, python, etc...). Is there a D scripting engine that can be easily integrated into a D project? A sort of "exec()". Something that works at compile time and run time possibly? If is a static string then it should be able to compile it at compile time, else, run time. Also, it would be nice if one could set up a unique state for the code to run in(so it can't be hacked by harmful coding), e.g., "exec(, state)", where state is the state used for the exec(passed along to the to use) for external function access and variable passing. Something that is fast as possible would be nice too! I know there this is quite a request, but hopefully there will be work on it. I'd love to see scripting capabilities included with most programs! This would be a start, at least, for my programs. Lua and python are already covered ([1] and [2]), for the D code I don't think so. While you can always call rdmd from D to compile and execute something in a script-like fashion it may not provide the level of integration you are looking for. On the other hand you should have a look at Adam Ruppe's script language that is written in D, largely benefits from CTFE but can be used at runtime too and has a JS-like syntax achieved by simply defining new D types (IIUC). That way you get a well-integrated easy to use language (although not quite polished). [3] [1]: http://code.dlang.org/packages/luad [2]: http://code.dlang.org/packages/pyd [3]: http://forum.dlang.org/thread/kuxfkakrgjaofkrdv...@forum.dlang.org
Re: Are there any D scripting engines for use with D?
On 2016-01-04 18:40:03 +, Jason Jeffory said: We have many scripting engines available for use in D more or less(lua, python, etc...). Is there a D scripting engine that can be easily integrated into a D project? A sort of "exec()". Something that works at compile time and run time possibly? If is a static string then it should be able to compile it at compile time, else, run time. Also, it would be nice if one could set up a unique state for the code to run in(so it can't be hacked by harmful coding), e.g., "exec(, state)", where state is the state used for the exec(passed along to the to use) for external function access and variable passing. Something that is fast as possible would be nice too! I know there this is quite a request, but hopefully there will be work on it. I'd love to see scripting capabilities included with most programs! This would be a start, at least, for my programs. The fastest one would probably be Lua - http://code.dlang.org/search?q=lua But there are other options: Python - http://code.dlang.org/packages/pyd Javascript - http://code.dlang.org/search?q=javascript and http://pointersgonewild.com/higgs/ Croc (previously miniD, a scripting language implemented in D) - http://jfbillingsley.com/croc/
Re: Threading to prevent GUI Freeze
On Monday, 4 January 2016 at 18:04:34 UTC, TheDGuy wrote: On Monday, 4 January 2016 at 17:33:28 UTC, Gerald wrote: On Monday, 4 January 2016 at 16:13:50 UTC, TheDGuy wrote: [...] Yes, you need it. The extern (C) function is what GDK invokes on idle. In any GUI application there is a lot of idle time waiting for events, what the addThreadIdle allows you to do is take advantage of this and tell GTK that whenever it's sitting around doing nothing, give this function a call. [...] Okay, thanks alot for your help. I think i will need some time to understand this but one last question: Do the errors come from the fact at i didn't use those GTK thread mechanisms or that my function is not "spawnable"? "std.concurrency.spawn(F, T...)(F fn, T args) if(isSpawnable!(F,T))" "Error: template std.concurrency.spawn cannot deduce function from argument types!()(void delegate(Context cr, Widget widget), Scoped Widget), candidates are:" Keep in mind I know nothing about Cairo and I don't have time to try your code, but what happens if you remove the Scoped template from the Context parameter? Also, have you checked if Cairo is thread-safe the way you are using it in the spawned function? I'm not sure if Cairo has the same restrictions that GTK widgets do.
Are there any D scripting engines for use with D?
We have many scripting engines available for use in D more or less(lua, python, etc...). Is there a D scripting engine that can be easily integrated into a D project? A sort of "exec()". Something that works at compile time and run time possibly? If is a static string then it should be able to compile it at compile time, else, run time. Also, it would be nice if one could set up a unique state for the code to run in(so it can't be hacked by harmful coding), e.g., "exec(, state)", where state is the state used for the exec(passed along to the to use) for external function access and variable passing. Something that is fast as possible would be nice too! I know there this is quite a request, but hopefully there will be work on it. I'd love to see scripting capabilities included with most programs! This would be a start, at least, for my programs.
Re: Threading to prevent GUI Freeze
On Monday, 4 January 2016 at 17:33:28 UTC, Gerald wrote: On Monday, 4 January 2016 at 16:13:50 UTC, TheDGuy wrote: [...] Yes, you need it. The extern (C) function is what GDK invokes on idle. In any GUI application there is a lot of idle time waiting for events, what the addThreadIdle allows you to do is take advantage of this and tell GTK that whenever it's sitting around doing nothing, give this function a call. [...] Okay, thanks alot for your help. I think i will need some time to understand this but one last question: Do the errors come from the fact at i didn't use those GTK thread mechanisms or that my function is not "spawnable"? "std.concurrency.spawn(F, T...)(F fn, T args) if(isSpawnable!(F,T))" "Error: template std.concurrency.spawn cannot deduce function from argument types!()(void delegate(Context cr, Widget widget), Scoped Widget), candidates are:"
Re: Strange 'memset' error when using std.range.repeat and std.array.array
On Monday, 4 January 2016 at 14:25:30 UTC, Marc Schütz wrote: On Monday, 4 January 2016 at 12:20:09 UTC, Ur@nuz wrote: On Monday, 4 January 2016 at 12:00:32 UTC, tcak wrote: [...] Yes. It's Ubuntu 14. It works when it's in the separate example, but not working inside my project. The strange thing is that it working in another place inside the same application. So I don't know what to think about it. Maybe this problem occurs only when some amount of memori is being allocated or something.. What is the value of `newIndentCount` when this happens? Could it be it is too big, or negative? If not, you could try reducing your program using dustmite: https://github.com/CyberShadow/DustMite/wiki/Detecting-a-specific-segfault The issue was trivial. I decreased variable with 0 value and got OutOfMemory error.
Re: question about the implementation of Variant
On Monday, 4 January 2016 at 09:13:25 UTC, Jonathan M Davis wrote: On Monday, January 04, 2016 07:30:50 aki via Digitalmars-d-learn wrote: But wait, how does GC detect there still be a live reference to the object Foo? Because store is just a fix sized array of bytes. ubyte[size] store; GC cannot be aware of the reference, right? As I understand it, the GC doesn't actually care about whether something is a pointer when it tries to figure out whether something refers to something - or at least, it'll treat integers as if they were pointers so that if you tried to do something like size_t i; { auto p = new int(5); i = cast(size_t)p; } // GC will not collect p even if it runs now then the fact that i matches the value of the address that p points to is enough for the GC to not collect the memory pointed to by p, even if there are no longer any pointers referring to it. This prevents problems when you do stuff like cast pointers to integers to store their values (which normally is crazy but on rare occasions makes sense). The downside is that the GC then has to treat all integers as if they were pointers, so if you have an integer whose value happens to match that of a memory address in GC-allocated memory (a so called false pointer), then that memory won't be freed, even if nothing is really pointing to it anymore. Fortunately, however, false pointers are primarily limited to 32-bit programs, and 64-bit programs don't have that problem because of how large their address space is (but 32-bit programs which allocate most of their address space can definitely run into problems where memory that should be freed isn't thanks to false pointers). - Jonathan M Davis That's only because we don't have a precise garbage collector and can't be relied upon. It's more of a bug / limitation rather than something to actually use. In the case of std.variant, it's not just byte[size] store, it's actually a union: union { ubyte[size] store; // conservatively mark the region as pointers static if (size >= (void*).sizeof) void*[size / (void*).sizeof] p; } Which tells the garbage collector that it may be pointers there, making it valid even for precise garbage collectors (which would have to conservatively handle such a union).
Re: Threading to prevent GUI Freeze
On Monday, 4 January 2016 at 16:13:50 UTC, TheDGuy wrote: Thanks for your example code. Do i need those extern (C) function? Yes, you need it. The extern (C) function is what GDK invokes on idle. In any GUI application there is a lot of idle time waiting for events, what the addThreadIdle allows you to do is take advantage of this and tell GTK that whenever it's sitting around doing nothing, give this function a call. The idea is that you spawn a thread that does your work and when GTK invokes your thread idle callback where you can check the status of the thread and update the UI accordingly. For example, let's say you need to render a highly complicated graph that takes a few minutes to complete. You could spawn a thread that renders it into an off-line buffer of some sort and once completed sends a message to the GTK main thread using std.concurrency. At some point GTK calls your thread idle callback and you simply invoke the std.concurrency.receive and see a message saying the graph has been rendered is available, and if so, copy it into the appropriate GTK widget. The important thing to understand is that the thread idle callback happens in the GTK main thread so it is completely safe to update GTK widgets from here. The other thing to understand is that whatever you work you do in the callback must be short, if you don't return in a reasonable amount of time you are blocking the main GTK thread. As a result it really should only be used as a mechanism to track work progress in whatever threads you have spawned. The GTK thread idle callback works beautifully with D's std.concurrency send and receive mechanism. Note the code I pointed you to in that D github Issue abstracts the extern (C) function from you and allows you to use normal D delegates as callbacks. The issue was created to get this incorporated into GtkD as I agree the framework should abstract this. Why is it not possible to write the value to the TreeView in D? I don't understand what you mean as of course it's possible to update value's in a TreeView. Do you mean why am I updating it from the callback (i.e. the C function)? The code here is an artificial example where it is simply updating the treeview with an iterating number generated in a separate thread. The results being posted to the TreeView could just as easily be a resultset from a long running database query, a complicated mathematical expression, etc. Hopefully the previous explanation helps you understand what the callback is doing. You can see a more real world example of GtkD multi-threading in this application I wrote called Visual Grep (https://github.com/gnunn1/vgrep), it puts a GTK GUI around grep with all searches running in background threads and updating Gtk TreeView as results come in. It also uses the delegate code linked in that issue which originally came from an application called grestful. Note Visual Grep was my first ever D/GtkD program so there is some ugh code in there, but hopefully it can act as an additional source of info for you.
Re: Size of Compiled Program
On Monday, 4 January 2016 at 14:01:18 UTC, Basile B. wrote: On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke wrote: [...] - if debug info are generated this increases the size. - if bounds checking is turned off there is some code generated for each array operation - if contracts are not off there is a lot of assertion that will be generated see also some clues here: http://forum.dlang.org/post/mailman.20.1441974998.22025.digitalmars-d-le...@puremagic.com Ah, thank you for that Link!
Re: Size of Compiled Program
On Monday, 4 January 2016 at 16:56:15 UTC, Martin Tschierschke with the "same" Ubuntu release, I got an error, may be its 32 not 64 Bit? Any hint? Yeah, probably.
Re: Size of Compiled Program
On Monday, 4 January 2016 at 14:51:59 UTC, Adam D. Ruppe wrote: On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke wrote: When I was writing a small speed test - D versus Ruby The smallest possible ruby program has about ~5 MB of dependencies, outside the operating system (the ruby runtime itself). The D program has none. It carries its runtime with it, which makes the executable a bit larger to compensate but helps compatibility with other computers because the user doesn't have to hunt down obscure D runtime packages. Oh, thats interesting. When I tried to run the compiled "prime" on my notebook, with the "same" Ubuntu release, I got an error, may be its 32 not 64 Bit? Any hint?
Re: Size of Compiled Program
On Monday, 4 January 2016 at 14:16:54 UTC, Marc Schütz wrote: On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke wrote: When I was writing a small speed test - D versus Ruby, calculating the first n prime numbers, I realized, that for small n Ruby may be faster, than compiling and executing with D. But for n = 1,000,000 D outperforms Ruby by app. 10x. Looking at the size of my prime executable, it was around 800 kB with DMD and even with optimization and "gdc -Os" > 1 MB. Why is such a short program resulting in a so big binary? That's probably basic these compilers statically link the runtime (and standard?) libraries by default. Compiling your program with `ldc2 -O3`, I get a binary of 28K, and stripping gets it down to 17K. Ok, I will try ldc2, too.
Re: Threading to prevent GUI Freeze
I wrote a demo for GtkD showing how multi-threading and D work together, it's in the demos/gtkD/DemoMultithread folder of GtkD, hopefully it will be helpful. However this example it is based on using the GTk threadIdle callback which is generally preferred over the locking methods you show above, obviously though your use case may vary but keep in mind the locking methods have been deprecated, see the GTK 3 reference manual here: https://developer.gnome.org/gdk3/stable/gdk3-Threads.html You also see this GtkD issue here for https://github.com/gtkd-developers/GtkD/issues/137 for some code on how to use Delgates with gdk_threads_add_idle (i.e. GtkD gdk.Threads.threadsAddIdle). Thanks for your example code. Do i need those extern (C) function? Why is it not possible to write the value to the TreeView in D?
Re: Threading to prevent GUI Freeze
On Monday, 4 January 2016 at 15:28:56 UTC, TheDGuy wrote: On Monday, 4 January 2016 at 15:07:12 UTC, Luis wrote: On Monday, 4 January 2016 at 14:31:04 UTC, TheDGuy wrote: [...] Before doing anything with threads and GTK, you should read this : http://blogs.operationaldynamics.com/andrew/software/gnome-desktop/gtk-thread-awareness Okay, so i have to do it like this on every function i use from GTKD? threadsInit(); threadsEnter(); GtkAllocation size; widget.getAllocation(size); threadsLeave(); I wrote a demo for GtkD showing how multi-threading and D work together, it's in the demos/gtkD/DemoMultithread folder of GtkD, hopefully it will be helpful. However this example it is based on using the GTk threadIdle callback which is generally preferred over the locking methods you show above, obviously though your use case may vary but keep in mind the locking methods have been deprecated, see the GTK 3 reference manual here: https://developer.gnome.org/gdk3/stable/gdk3-Threads.html You also see this GtkD issue here for https://github.com/gtkd-developers/GtkD/issues/137 for some code on how to use Delgates with gdk_threads_add_idle (i.e. GtkD gdk.Threads.threadsAddIdle).
Re: Integer literals
On 1/4/16 10:33 AM, ric maicle wrote: On Monday, 04 January, 2016 10:58 PM, Adam D. Ruppe wrote: On Monday, 4 January 2016 at 14:54:29 UTC, ric maicle wrote: 0U .. 4_294_967_296U in the table Decimal Literal Types has a typo. Shouldn't the range end with 4_294_967_295U? The x .. y syntax excludes y. So 0..3 covers 0, 1, 2. It excludes 3. I copied part of the table here: 0 .. 2_147_483_647 2_147_483_648 .. 9_223_372_036_854_775_807 0L .. 9_223_372_036_854_775_807L 0U .. 4_294_967_296U 4_294_967_296U .. 18_446_744_073_709_551_615U 0UL .. 18_446_744_073_709_551_615UL If the range is x to y-1 shouldn't the rest of the other ending ranges also be one greater than the maximum value of their types? Yes, that is a typo. https://github.com/D-Programming-Language/dlang.org/pull/1181 Thanks -Steve
Re: Integer literals
On Monday, 04 January, 2016 10:58 PM, Adam D. Ruppe wrote: On Monday, 4 January 2016 at 14:54:29 UTC, ric maicle wrote: 0U .. 4_294_967_296U in the table Decimal Literal Types has a typo. Shouldn't the range end with 4_294_967_295U? The x .. y syntax excludes y. So 0..3 covers 0, 1, 2. It excludes 3. I copied part of the table here: 0 .. 2_147_483_647 2_147_483_648 .. 9_223_372_036_854_775_807 0L .. 9_223_372_036_854_775_807L 0U .. 4_294_967_296U 4_294_967_296U .. 18_446_744_073_709_551_615U 0UL .. 18_446_744_073_709_551_615UL If the range is x to y-1 shouldn't the rest of the other ending ranges also be one greater than the maximum value of their types?
Re: Threading to prevent GUI Freeze
On Monday, 4 January 2016 at 15:07:12 UTC, Luis wrote: On Monday, 4 January 2016 at 14:31:04 UTC, TheDGuy wrote: [...] Before doing anything with threads and GTK, you should read this : http://blogs.operationaldynamics.com/andrew/software/gnome-desktop/gtk-thread-awareness Okay, so i have to do it like this on every function i use from GTKD? threadsInit(); threadsEnter(); GtkAllocation size; widget.getAllocation(size); threadsLeave();
Re: @property not available for classes?
On 1/3/16 2:25 PM, Jacob Carlborg wrote: On 2016-01-03 18:48, Steven Schveighoffer wrote: class constructor requirements are much different from struct constructor requirements. There's also no implicit constructor that initializes all members as there is for structs. To clarify, there's a default (implicit) constructor that initializes all members to what they are set to in the class declaration. But you cannot pass in any arguments to the default constructor. Hmm, technically that might actually not be the constructor that initializes the members, not sure. Technically, the GC initializes the data as given by the TypeInfo before the ctor is run. I believe the default ctor does nothing, not even sure if it exists or is called. For simplicity, you can assume there is one. But yes, I was referring to the struct ctor that allows you to initialize one or more of the members to non-default values. -Steve
Re: Threading to prevent GUI Freeze
On Monday, 4 January 2016 at 14:31:04 UTC, TheDGuy wrote: Hello, i use GTKD to draw some stuff on a DrawingArea. Because it needs some time to calculate i want to outsource those calculation so that the GUI doesn't freeze. I tried it with "std.concurrency" like this: bool drawCallback(Scoped!Context cr, Widget widget){ writeln("init"); spawn(&render, cr, widget); return true; } void render(Context cr, Widget widget){ Renderer renderer = new Renderer(new Vector3D(0,0,0), cr, widget); int i = 0; while(i < 4){ renderer.renderOneStep(); i++; } renderer.DisplayResult(); } But i get: "std.concurrency.spawn(F, T...)(F fn, T args) if(isSpawnable!(F,T))" "Error: template std.concurrency.spawn cannot deduce function from argument types!()(void delegate(Context cr, Widget widget), Scoped Widget), candidates are:" Before doing anything with threads and GTK, you should read this : http://blogs.operationaldynamics.com/andrew/software/gnome-desktop/gtk-thread-awareness
Re: Integer literals
On Monday, 4 January 2016 at 14:54:29 UTC, ric maicle wrote: 0U .. 4_294_967_296U in the table Decimal Literal Types has a typo. Shouldn't the range end with 4_294_967_295U? The x .. y syntax excludes y. So 0..3 covers 0, 1, 2. It excludes 3.
Integer literals
I was rereading the Integer Literals section and trying out some code when I came across a couple of error messages on integer overflows. I have reproduced the code below for reference. void main() { // The maximum long value is ...807 // The following line produces an error message: // Error: signed integer overflow auto a = 9_223_372_036_854_775_808; // The maximum ulong value is ...615 // The following line produces an error message: // Error: integer overflow auto g = 18_446_744_073_709_551_616U; } I just wanted to point out that the second error message might be consistent if it says 'Error: unsigned integer overflow' in comparison to the first error message. Also, I noticed under the Integer Literal section of the D reference document (http://dlang.org/spec/lex.html) that the range of uint 0U .. 4_294_967_296U in the table Decimal Literal Types has a typo. Shouldn't the range end with 4_294_967_295U? Here's a snippet: import std.stdio; void main() { writeln(typeof(4_294_967_295U).stringof); writeln(typeof(4_294_967_296U).stringof); }
Re: Size of Compiled Program
On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke wrote: When I was writing a small speed test - D versus Ruby The smallest possible ruby program has about ~5 MB of dependencies, outside the operating system (the ruby runtime itself). The D program has none. It carries its runtime with it, which makes the executable a bit larger to compensate but helps compatibility with other computers because the user doesn't have to hunt down obscure D runtime packages.
Threading to prevent GUI Freeze
Hello, i use GTKD to draw some stuff on a DrawingArea. Because it needs some time to calculate i want to outsource those calculation so that the GUI doesn't freeze. I tried it with "std.concurrency" like this: bool drawCallback(Scoped!Context cr, Widget widget){ writeln("init"); spawn(&render, cr, widget); return true; } void render(Context cr, Widget widget){ Renderer renderer = new Renderer(new Vector3D(0,0,0), cr, widget); int i = 0; while(i < 4){ renderer.renderOneStep(); i++; } renderer.DisplayResult(); } But i get: "std.concurrency.spawn(F, T...)(F fn, T args) if(isSpawnable!(F,T))" "Error: template std.concurrency.spawn cannot deduce function from argument types!()(void delegate(Context cr, Widget widget), Scoped Widget), candidates are:"
Re: Strange 'memset' error when using std.range.repeat and std.array.array
On Monday, 4 January 2016 at 12:20:09 UTC, Ur@nuz wrote: On Monday, 4 January 2016 at 12:00:32 UTC, tcak wrote: On Monday, 4 January 2016 at 10:50:17 UTC, Ur@nuz wrote: Sorry, the actual code is: ... lines ~= ' '.repeat.take(newIndentCount).array; ...with character quotes. But it still fails with error described in stack trace in Gcx.bigAlloc() What's your OS? On Linux x64, it works without any error. Yes. It's Ubuntu 14. It works when it's in the separate example, but not working inside my project. The strange thing is that it working in another place inside the same application. So I don't know what to think about it. Maybe this problem occurs only when some amount of memori is being allocated or something.. What is the value of `newIndentCount` when this happens? Could it be it is too big, or negative? If not, you could try reducing your program using dustmite: https://github.com/CyberShadow/DustMite/wiki/Detecting-a-specific-segfault
Re: Size of Compiled Program
On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke wrote: When I was writing a small speed test - D versus Ruby, calculating the first n prime numbers, I realized, that for small n Ruby may be faster, than compiling and executing with D. But for n = 1,000,000 D outperforms Ruby by app. 10x. Looking at the size of my prime executable, it was around 800 kB with DMD and even with optimization and "gdc -Os" > 1 MB. Why is such a short program resulting in a so big binary? That's probably basic these compilers statically link the runtime (and standard?) libraries by default. Compiling your program with `ldc2 -O3`, I get a binary of 28K, and stripping gets it down to 17K.
Re: Size of Compiled Program
On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke wrote: When I was writing a small speed test - D versus Ruby, calculating the first n prime numbers, I realized, that for small n Ruby may be faster, than compiling and executing with D. But for n = 1,000,000 D outperforms Ruby by app. 10x. Looking at the size of my prime executable, it was around 800 kB with DMD and even with optimization and "gdc -Os" > 1 MB. Why is such a short program resulting in a so big binary? You have the runtime and phobos compiled with your program. But also: - if debug info are generated this increases the size. - if bounds checking is turned off there is some code generated for each array operation - if contracts are not off there is a lot of assertion that will be generated see also some clues here: http://forum.dlang.org/post/mailman.20.1441974998.22025.digitalmars-d-le...@puremagic.com
Size of Compiled Program
When I was writing a small speed test - D versus Ruby, calculating the first n prime numbers, I realized, that for small n Ruby may be faster, than compiling and executing with D. But for n = 1,000,000 D outperforms Ruby by app. 10x. Looking at the size of my prime executable, it was around 800 kB with DMD and even with optimization and "gdc -Os" > 1 MB. Why is such a short program resulting in a so big binary? - import std.stdio; import std.conv; int[] prime; // Dynamic Array of Prime // Ist n durch eine der zahlen in prime teilbar? bool teilbar(int n){ for(auto i=0; prime[i]*prime[i]<=n ; i++){ if (n%prime[i]==0) return true; } return false; } void main(string[] args) // first parameter number of primes to calculate { auto anzahl = 10; // default prime ~= 2; // first element of the array if(args.length==2){ anzahl = to!int(args[1]);} auto pruefe=1; while (prime.length <= anzahl){ pruefe+=2; if(!teilbar(pruefe)){ write(" ",pruefe); prime ~= pruefe; // append the array } } write("\n das wars...:",prime.length); }
Re: to!double different from cast(double)
On 04.01.2016 09:22, Ali Çehreli wrote: void main() { const l = long.max; assert(l != l.to!double); // passes assert(l != cast(double)l);// FAILS } Is there a good explanation for this difference? I would expect both expressions to be compiled the same way. (I am aware that the != operator takes two doubles, meaning that the left-hand side is converted to 'double' before the comparison.) I suspect this is due to D allowing floating point operations to happen with higher precision than requested by the program. The comparisons may be done with `real` precision, and `l.to!double` is cut down to double precision while `cast(double)l` is not.
Re: CMake support for D
On Monday, 4 January 2016 at 12:40:23 UTC, Dibyendu Majumdar wrote: Thanks for suggesting dub, will check it out. Also premake seems to support D so that is another option. Another alternative is reggae which supports mixed code base: https://github.com/atilaneves/reggae and can generate ninja/make/tup build rules (similarly to cmake).
Re: CMake support for D
On Monday, 4 January 2016 at 08:28:03 UTC, Luis wrote: I suggest use dub instead of cmake. I did a try to use cmake some time ago (a few years ago, before dub), and was a nightmare to get ir working on GNU/Linux and Windows. With dub , simply works fine with a simple json file. CMake has worked well for me for C/C++ projects, on Windows, Linux and OSX. Pity no official support for D. I need support for apps that have a mixed code base not just D. Thanks for suggesting dub, will check it out. Also premake seems to support D so that is another option. Regards
Re: CMake support for D
On Mon, 2016-01-04 at 08:28 +, Luis via Digitalmars-d-learn wrote: > > I suggest use dub instead of cmake. I did a try to use cmake some > time ago (a few years ago, before dub), and was a nightmare to > get ir working on GNU/Linux and Windows. With dub , simply works > fine with a simple json file. The problem though is twofold: 1. IDE support, cf. CLion required CMake. 2. Getting things packaged in Debian/Fedora. As far as I am aware, Dub is not yet packaged by Debian and Fedora and so cannot be used for creating Debian or Fedora packages. If Dub could be packaged then it opens up a whole new world of possibilities. For now though use of SCons and CMake is nigh on required for projects aiming to get packaged. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Can't find windows' CreateThread function / concurrency.spawn crashes host application
On 02.01.2016 18:41, alkololl wrote: On Saturday, 2 January 2016 at 16:42:46 UTC, Rainer Schuetze wrote: On 02.01.2016 16:34, alkololl wrote: On Saturday, 2 January 2016 at 01:44:46 UTC, Adam D. Ruppe wrote: [...] Thanks for your reply. I replaced my switch statement with the one behind the link you left but the result (no result) stays the same. The Dll doesn't get unloaded. Not until I close the host application. D needs "implicite thread local storage" to implement thread local variables, but Windows XP and earlier versions do not support this for DLLs dynamically loaded through LoadLibrary. The D runtime implements the part necessary for loading, but does not support unloading. As a consequence it sets the DLL to never unload. If you are actually running XP, you can check https://github.com/denis-sh/hooking. IIRC Denis Shelomovskij implemented the missing parts. What? I'm actually running Windows 7. For me it's inevitable to not unload the D Dll dynamically. Isn't there some kind of workaround or a sneaky hack to solve this? If you run Windows 7, I guess the runtime patch is not the issue here. Have you tried to load the DLL explicitely (without injecting it)? Does it unload correctly in this case? If not, it should ease debugging the problem.
Re: Strange 'memset' error when using std.range.repeat and std.array.array
On Monday, 4 January 2016 at 12:00:32 UTC, tcak wrote: On Monday, 4 January 2016 at 10:50:17 UTC, Ur@nuz wrote: Sorry, the actual code is: ... lines ~= ' '.repeat.take(newIndentCount).array; ...with character quotes. But it still fails with error described in stack trace in Gcx.bigAlloc() What's your OS? On Linux x64, it works without any error. Yes. It's Ubuntu 14. It works when it's in the separate example, but not working inside my project. The strange thing is that it working in another place inside the same application. So I don't know what to think about it. Maybe this problem occurs only when some amount of memori is being allocated or something..
Re: Strange 'memset' error when using std.range.repeat and std.array.array
On Monday, 4 January 2016 at 10:50:17 UTC, Ur@nuz wrote: Sorry, the actual code is: ... lines ~= ' '.repeat.take(newIndentCount).array; ...with character quotes. But it still fails with error described in stack trace in Gcx.bigAlloc() What's your OS? On Linux x64, it works without any error.
Re: Strange 'memset' error when using std.range.repeat and std.array.array
Sorry, the actual code is: ... lines ~= ' '.repeat.take(newIndentCount).array; ...with character quotes. But it still fails with error described in stack trace in Gcx.bigAlloc()
Strange 'memset' error when using std.range.repeat and std.array.array
Need some help)... Having the following chunk of code: string[] lines; ... if( firstIndentStyle == IndentStyle.space ) { lines ~= " ".repeat.take(newIndentCount).array; } else //Tabs { lines ~= "\t".repeat.take(newIndentCount).array; //This causes strange 'memset' error } This code fails with seg fault in memset. And I don't know why? here goes stack trace: declarative [20930] [cores: 3] Thread #1 [declarative] 20930 [core: 3] (Suspended : Signal : SIGSEGV:Segmentation fault) gc.gc.Gcx.bigAlloc() at 0x4dbc73 gc.gc.GC.malloc() at 0x4d9375 gc_malloc() at 0x4cc308 core.memory.GC.malloc() at 0x4cbe64 std.array.__T14arrayAllocImplVbi0TAaTmZ.arrayAllocImpl() at array.d:628 0x4a1185 std.array.__T18uninitializedArrayTAaTmZ.uninitializedArray() at array.d:533 0x4a1155 std.array.__T5arrayTS3std5range43__T4TakeTS3std5range13__T6RepeatTaZ6RepeatZ4TakeZ.array() at array.d:119 0x4bc699 std.array.__T5arrayTS3std5range43__T4TakeTS3std5range13__T6RepeatTaZ6RepeatZ4TakeZ.array() at array.d:119 0x4bc5fb declarative.parser.__T6ParserTS11declarative11lexer_tools76__T16TextForwardRangeTAyaVS11declarative6common14LocationConfigS5i1i1i1i1i1Z16TextForwardRangeZ.Parser.parseMixedBlockData() at parser.d:437 0x4c26e3 declarative.parser.__T6ParserTS11declarative11lexer_tools76__T16TextForwardRangeTAyaVS11declarative6common14LocationConfigS5i1i1i1i1i1Z16TextForwardRangeZ.Parser.parseMixedBlock() at parser.d:481 0x4c29fa <...more frames...> Tried to reduce example into the folowing (and it is working!): module bug_test; import std.stdio; import std.range; void main() { import std.array: array; string[] lines; size_t newIndentCount = 8; lines ~= ' '.repeat.take(newIndentCount).array; writeln( lines ); } Could someone imagine why this could happen?))
Re: question about the implementation of Variant
On Monday, January 04, 2016 07:30:50 aki via Digitalmars-d-learn wrote: > But wait, how does GC detect there still be a live reference to > the object Foo? > Because store is just a fix sized array of bytes. > ubyte[size] store; > GC cannot be aware of the reference, right? As I understand it, the GC doesn't actually care about whether something is a pointer when it tries to figure out whether something refers to something - or at least, it'll treat integers as if they were pointers so that if you tried to do something like size_t i; { auto p = new int(5); i = cast(size_t)p; } // GC will not collect p even if it runs now then the fact that i matches the value of the address that p points to is enough for the GC to not collect the memory pointed to by p, even if there are no longer any pointers referring to it. This prevents problems when you do stuff like cast pointers to integers to store their values (which normally is crazy but on rare occasions makes sense). The downside is that the GC then has to treat all integers as if they were pointers, so if you have an integer whose value happens to match that of a memory address in GC-allocated memory (a so called false pointer), then that memory won't be freed, even if nothing is really pointing to it anymore. Fortunately, however, false pointers are primarily limited to 32-bit programs, and 64-bit programs don't have that problem because of how large their address space is (but 32-bit programs which allocate most of their address space can definitely run into problems where memory that should be freed isn't thanks to false pointers). - Jonathan M Davis
Re: to!double different from cast(double)
On 01/04/2016 12:22 AM, Ali Çehreli wrote: > assert(l != l.to!double); // passes > assert(l != cast(double)l);// FAILS I've realized that I had the -m32 switch on unintentionally. The above results are for when -m32 is used. (I am on a 64-bit system.) Without -m32 both checks fail and the universe makes sense. Still, would you consider it a bug that the results are different for -m32? Ali
Re: CMake support for D
On Sunday, 3 January 2016 at 17:30:15 UTC, Dibyendu Majumdar wrote: Does CMake recognise D in the enable_language command? If not is there a workaround? Thanks and Regards Dibyendu I suggest use dub instead of cmake. I did a try to use cmake some time ago (a few years ago, before dub), and was a nightmare to get ir working on GNU/Linux and Windows. With dub , simply works fine with a simple json file.
to!double different from cast(double)
I was writing an example to show that not every 'long' value can be represented by a 'double'. (They are both 64 bits; but for 'double', some of those bits are parts of the exponent, not the mantissa.) Although my demonstration works with to!double, the compiler does something different and the cast(double) test fails: import std.conv; void main() { const l = long.max; assert(l != l.to!double); // passes assert(l != cast(double)l);// FAILS } Is there a good explanation for this difference? I would expect both expressions to be compiled the same way. (I am aware that the != operator takes two doubles, meaning that the left-hand side is converted to 'double' before the comparison.) Ali