Re: GUI development libraries in D?
On 2012-09-25 23:52, Matthew Turner wrote: Hello, I'm wondering if there is any library for making a GUI with D. If not, what would you recommend for that? Could I just use c++ libraries? https://github.com/d-widget-toolkit/dwt I think using C++ libraries would be quite hard and limited. -- /Jacob Carlborg
Re: Runtime termination hook?
On 2012-09-26 07:37, Sean Kelly wrote: A shared static dtor? Didn't think of that. When exactly are those run? I'm looking for something corresponding to this Java method: http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29 -- /Jacob Carlborg
Re: Runtime termination hook?
On Sep 25, 2012, at 12:44 PM, Jacob Carlborg wrote: > Is there an event that I can hook into which is called when the runtime is > terminated? A shared static dtor?
Re: GUI development libraries in D?
Al 25/09/12 23:52, En/na Matthew Turner ha escrit: > Hello, > > I'm wondering if there is any library for making a GUI with D. If not, what > would you recommend for that? Could I just use c++ libraries? > https://github.com/gtkd-developers/GtkD -- Jordi Sayol
Re: How do I use std.zlib to write a struct of data to a binary file with compression?
On Tuesday, 25 September 2012 at 18:08:44 UTC, Justin Whear wrote: I wrote up a quick example program and pasted it here: http://dpaste.dzfl.pl/f1699d07 Hope that helps you out. OK, I think I am working this out. Let's say I want to write the data to a gzipped file that will be inter-operable with gzip at the command line. I think I do something like the following: auto mem = new MemoryStream(); mem.writeExact(foo.ptr, foo.length * A.sizeof); auto gzdat = new Compress(9, HeaderFormat.gzip); gzdat.compress(mem.data); But then, what do I do with gzdat? Do I try to write it to a file like this: auto fout = new std.stream.File("data.bin.gz", FileMode.OutNew); fout.writeExact(gzdat.ptr, gzdat.sizeof); Something is wrong though. Hmm ... TJB
GUI development libraries in D?
Hello, I'm wondering if there is any library for making a GUI with D. If not, what would you recommend for that? Could I just use c++ libraries? Thank you, Matt
Re: How do I use std.zlib to write a struct of data to a binary file with compression?
On Tue, 25 Sep 2012 18:08:44 +, Justin Whear wrote: > On Tue, 25 Sep 2012 03:25:37 +0200, TJB wrote: > >>> Since you're already set up with the Stream interface, try creating a >>> MemoryStream instead of a BufferedFile. Write to the stream just as >>> you are now, then use the .data() property (on MemoryStream's >>> superclass, >>> TArrayStream) to get an array of raw bytes. You can feed this array >>> into the compress function in std.zlib to produce a new (hopefully >>> shorter) >>> array of bytes that contains the compressed data. Simply write this >>> compressed data to a file with `fout.writeExact(compressed.ptr, >>> compressed.length)` and you're done. >>> >>> Since uncompress works better if you know the exact size of the >>> uncompressed data, you might also consider writing the uncompressed >>> size of the data to your output file before the compressed data. >>> >>> Justin >> >> Ok, I think I get it. Can you help me set up the first part, >> writing to the MemoryStream? >> >> TJB > > I wrote up a quick example program and pasted it here: > http://dpaste.dzfl.pl/f1699d07 > > Hope that helps you out. I should point out that in my example, the writing to the MemoryStream is not strictly necessary. I could have simply cast the foo array to an array of bytes and passed that into the compress function. But if you're already set up for writing raw data into a stream, the MemoryStream will help you minimize code changes as well as facilitate more complex scenarios.
Re: How do I use std.zlib to write a struct of data to a binary file with compression?
On Tuesday, 25 September 2012 at 18:08:44 UTC, Justin Whear wrote: I wrote up a quick example program and pasted it here: http://dpaste.dzfl.pl/f1699d07 Hope that helps you out. Justin, Thanks so much! Very helpful!!! TJB
Runtime termination hook?
Is there an event that I can hook into which is called when the runtime is terminated? -- /Jacob Carlborg
Re: Zipped sorting
On 25-Sep-12 15:23, bearophile wrote: Dmitry Olshansky: Analyzing asm dump should help. In this case it's a good amount of asm code. This sounds like you are not interested in the cause of this at all ;) I've dig it and it looks mostly fine. However for a small number of elements it will most of the time will fall through to the insertion sort, so the analysis can be limited to just testing your bubble/etc. sort vs Phobos equivalent. Just grab optimisticInsertionSort out of Phobos std.algorithm and compare. But either way zip-sort heavily relies on proper inlining and I suspect it's not fully "unrolled". I don't know if that's enough. Well the other way to test is sort array of tuples with std.sort and then with your function. Also it's important to see the actual code that you compare otherwise we are just wasting time here. Did you try DMD or other compilers? In past I have used LDC often, but nowadays I use only DMD. Well I'd try GDC just to check if it's a codegen/optimizer issue. -- Dmitry Olshansky
Re: How do I use std.zlib to write a struct of data to a binary file with compression?
On Tue, 25 Sep 2012 03:25:37 +0200, TJB wrote: >> Since you're already set up with the Stream interface, try creating a >> MemoryStream instead of a BufferedFile. Write to the stream just as >> you are now, then use the .data() property (on MemoryStream's >> superclass, >> TArrayStream) to get an array of raw bytes. You can feed this array >> into the compress function in std.zlib to produce a new (hopefully >> shorter) >> array of bytes that contains the compressed data. Simply write this >> compressed data to a file with `fout.writeExact(compressed.ptr, >> compressed.length)` and you're done. >> >> Since uncompress works better if you know the exact size of the >> uncompressed data, you might also consider writing the uncompressed >> size of the data to your output file before the compressed data. >> >> Justin > > Ok, I think I get it. Can you help me set up the first part, > writing to the MemoryStream? > > TJB I wrote up a quick example program and pasted it here: http://dpaste.dzfl.pl/f1699d07 Hope that helps you out.
Re: How can I hide implementation details when make a library
On Tuesday, September 25, 2012 13:58:00 Daniel Kozak wrote: > Yes, it works. Thanks a lot. > > However I still dont get it, why dmd generates all sources > instead of just public symbols and functions declarations A number of features do not work if not all of the source is available. In particular, functions can't be inlined if the compiler doesn't have their source, and any function which is used at compile time (using CTFE - compile time function evaluation) needs its full source and the source of every function that it calls. So, in general, it's pretty crippling to not have the full source available. Also, templates tend to be used quite heavily in D, and because templates aren't actually instantiated until they're used, their entire source must be in the .di file regardless, making it so that you _can't_ hide their code (C++ has exactly the same issue). So, in general, .di files don't make a lot of sense. But if all that anyone is doing is calling the functions at runtime, and it doesn't matter that they're not inlinable, and you don't need any of them to be templated (or it's okay for the few that are templated to have their full source in the .di file), then you can strip out the function bodies in .di files, and that _can_ be useful if you really need that, but pretty much no one's going to do that unless they have to (or just don't understand what they lose by doing so). - Jonathan M Davis
Re: Passing associative array to another thread
Dne 25.9.2012 18:19, Jacob Carlborg napsal(a): BTW, why do you need to use std.currency at all if it's immutable, just share it as a global. The whole point of immutable is that it can be freely shared among threads without any risks. It is not some single piece of data. I have a queue of tasks. Each task is a struct that contains among other things a user-supplied delegate and an AA with parameters for that delegate. These tasks are created somewhere, inserted into the queue and then executed in parallel. Once created they are not modified anywhere and should exist only in one instance that is passed to that delegate. It's just that I haven't found a better way to pass parameters that are unknown before to a delegate. Martin
Re: Passing associative array to another thread
On 2012-09-21 16:33, Martin Drasar wrote: Hi, I am using the std.concurrency module and I would like to send an associative array to another thread. If I try this: string[string] aa; someThread.send(aa); I get: Aliases to mutable thread-local data not allowed. And if I try to use this: immutable(string[string]) aa; someThread.send(aa); I get: /usr/include/d/dmd/phobos/std/variant.d(539): Error: *p is not mutable BTW, why do you need to use std.currency at all if it's immutable, just share it as a global. The whole point of immutable is that it can be freely shared among threads without any risks. -- /Jacob Carlborg
Re: How can I hide implementation details when make a library
On 2012-09-25 13:58, Daniel Kozak wrote: Yes, it works. Thanks a lot. However I still dont get it, why dmd generates all sources instead of just public symbols and functions declarations The source code is included to be able to inline the functions. It's probably has something to do with the metaprogramming features in D, like, static-if, string and template mixin, auto and several other features. There has been some discussion about this in the newsgroup which you should be able to find. One problem in particular is with "auto". For some reason the compiler won't do a full semantic analyze when generating import files, resulting it cannot resolve "auto". You also need to have the source code of a function to resolve return types declared as "auto". -- /Jacob Carlborg
Re: How can I hide implementation details when make a library
Yes, it works. Thanks a lot. However I still dont get it, why dmd generates all sources instead of just public symbols and functions declarations On Tuesday, 25 September 2012 at 11:39:56 UTC, Jacob Carlborg wrote: On 2012-09-25 13:39, Daniel Kozak wrote: Hello, I try to make for example some small library called libX. In C/C++ I can make libX.h(pp) and libX.c(xx), where libX.h will contain only interface for implementation from libX.c. How can I achive this in D2? When I trak dmd -o- -op -H libX.d it will generate libX.di, but this file always contains all source code from libX.d. It just strip comments. You can manually create .di files just as you would with C/C++.
Re: How can I hide implementation details when make a library
On 2012-09-25 13:39, Daniel Kozak wrote: Hello, I try to make for example some small library called libX. In C/C++ I can make libX.h(pp) and libX.c(xx), where libX.h will contain only interface for implementation from libX.c. How can I achive this in D2? When I trak dmd -o- -op -H libX.d it will generate libX.di, but this file always contains all source code from libX.d. It just strip comments. You can manually create .di files just as you would with C/C++. -- /Jacob Carlborg
How can I hide implementation details when make a library
Hello, I try to make for example some small library called libX. In C/C++ I can make libX.h(pp) and libX.c(xx), where libX.h will contain only interface for implementation from libX.c. How can I achive this in D2? When I trak dmd -o- -op -H libX.d it will generate libX.di, but this file always contains all source code from libX.d. It just strip comments.
Re: Zipped sorting
Dmitry Olshansky: Analyzing asm dump should help. In this case it's a good amount of asm code. But either way zip-sort heavily relies on proper inlining and I suspect it's not fully "unrolled". I don't know if that's enough. Did you try DMD or other compilers? In past I have used LDC often, but nowadays I use only DMD. Bye, bearophile
Re: FormattedRead hex string
On Monday, 24 September 2012 at 22:38:59 UTC, Jason Spencer wrote: On Monday, 24 September 2012 at 16:32:45 UTC, monarch_dodra wrote: On Monday, 24 September 2012 at 15:05:54 UTC, Jason Spencer wrote: I imagine there's a slick way to do this, but I'm not seeing it. I have a string of hex digits which I'd like to convert to an array of 8 ubytes: 0123456789abcdef --> [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF] void main(string[] args) { ubyte[8] b; formattedRead(args[1], "%(%s%)", &b); } I think that you are not supposed to use a static array: If there are not EXACTLY as many array elements as there are parse-able elements, then the formatted read will consider the parse to have failed. The sample code was just for testing convenience. In practice the string will be conditioned and known to have 16 characters in {0-9, a-f}. Try this, it's what you want, right? void main() { string s = " fff ff f"; ushort[] vals; formattedRead(s, "%(%x %)", &vals); writefln("%(%s - %)", vals); } Not quite. You've taken the liberty of using a delimiter--spaces. I have to take 16 contiguous, NON-delimited hex digits and produce 8 bytes. So I could read it as a uint64 (not uint16, as I mistakenly posted before), but then I'd have to byte-reverse it. I could use slicing and do a byte at a time. I just wondered if there were a slick way to get in-place data from a contiguous hex string. Thanks, Jason I am unsure if the non-support of %2x is by design, or just "not yet supported". Keep in mind that slicing a string *is* inplace. It is equivalent to pointer arithmetic. I'd just do a loop: void main() { string s = "0123456789abcdef"; ushort[8] vals; foreach(size_t i; 0..8) { string slice = s[2*i .. 2*(i+1)]; slice.formattedRead("%x", &vals[i]); } writeln(vals); } [1, 35, 69, 103, 137, 171, 205, 239] Will still get the job done pretty cleanly and efficiently. Chances are this is even faster and more efficient than a supposed "%(%2x%)" scheme, since you are lowering the complexity from a list of reads to a simple extract data. Alternatively, you could just use conv's "to" or "parse". I've had others argue that "ForamttedRead" is meant as an implementation detail, and should be used by other functions, but "consumers" shouldn't use it directly. I found this strange at first, but I've grown fond of the power of "to": import std.conv, std.stdio; void main() { string s = "0123456789abcdef"; ushort[8] vals; foreach(size_t i; 0..8) vals[i] = s[2*i .. 2*(i+1)].to!ushort(16); writeln(vals); } Pretty nice, no?