Re: Why is there no named parameter support?
On Tuesday, June 09, 2015 01:38:56 Timothee Cour via Digitalmars-d-learn wrote: > On Mon, Jun 8, 2015 at 11:32 PM, Jonathan M Davis via Digitalmars-d-learn < > digitalmars-d-learn@puremagic.com> wrote: > > > On Monday, June 08, 2015 23:18:50 Timothee Cour via Digitalmars-d-learn > > wrote: > > > nim has both overloading and named arguments (with reordering and > > defaults > > > allowed): http://nim-lang.org/docs/tut1.html#procedures-named-arguments > > > and it doesn't seem to cause issues. > > > > > > Is there a document / thread that explains the argument against named > > > arguments in more details than 'do not play well together' ? > > > > Probably not, but Walter was quite adamant when it was discussed at dconf > > that it's a disaster to mix named arguments and function overloading in the > > same language. Maybe it's not as bad as he thinks it is, but personally, I > > think that named arguments are a terrible idea in general, so I'm not about > > to try and support a position that tries to bring them into D. > > > > - Jonathan M Davis > > > > > I'd be very interested in reading more about those reasons beyond FUD. > The arguments in favor have been repeated many times over, and the only > argument against that I've heard ('overloading and named arguments do not > play well together') doesn't seem valid, given the precedent in nim. Then talk with Walter about it. Whether he's right or not is up for debate, but it's certainly not FUD. He gave good examples, but I don't remember what they were at this point. Personally, I hate how named arguments affect the API (e.g. the names of the parameters suddenly become part of the API), and for the most part, the only times that they're worth much is when you have so many function parameters that you should be creating structs to hold those values anyway. I don't want them in the language, and I'm very glad that Walter is against them, so I didn't feel the need to try and remember all he said about why they were a bad idea. - Jonathan M Davis
Re: Why is there no named parameter support?
On Mon, Jun 8, 2015 at 11:32 PM, Jonathan M Davis via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Monday, June 08, 2015 23:18:50 Timothee Cour via Digitalmars-d-learn > wrote: > > nim has both overloading and named arguments (with reordering and > defaults > > allowed): http://nim-lang.org/docs/tut1.html#procedures-named-arguments > > and it doesn't seem to cause issues. > > > > Is there a document / thread that explains the argument against named > > arguments in more details than 'do not play well together' ? > > Probably not, but Walter was quite adamant when it was discussed at dconf > that it's a disaster to mix named arguments and function overloading in the > same language. Maybe it's not as bad as he thinks it is, but personally, I > think that named arguments are a terrible idea in general, so I'm not about > to try and support a position that tries to bring them into D. > > - Jonathan M Davis > > I'd be very interested in reading more about those reasons beyond FUD. The arguments in favor have been repeated many times over, and the only argument against that I've heard ('overloading and named arguments do not play well together') doesn't seem valid, given the precedent in nim.
Re: Why is there no named parameter support?
On Monday, June 08, 2015 23:18:50 Timothee Cour via Digitalmars-d-learn wrote: > nim has both overloading and named arguments (with reordering and defaults > allowed): http://nim-lang.org/docs/tut1.html#procedures-named-arguments > and it doesn't seem to cause issues. > > Is there a document / thread that explains the argument against named > arguments in more details than 'do not play well together' ? Probably not, but Walter was quite adamant when it was discussed at dconf that it's a disaster to mix named arguments and function overloading in the same language. Maybe it's not as bad as he thinks it is, but personally, I think that named arguments are a terrible idea in general, so I'm not about to try and support a position that tries to bring them into D. - Jonathan M Davis
Re: Why is there no named parameter support?
nim has both overloading and named arguments (with reordering and defaults allowed): http://nim-lang.org/docs/tut1.html#procedures-named-arguments and it doesn't seem to cause issues. Is there a document / thread that explains the argument against named arguments in more details than 'do not play well together' ? On Mon, Jun 8, 2015 at 10:45 PM, Jonathan M Davis via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Monday, June 08, 2015 20:36:05 Yuxuan Shui via Digitalmars-d-learn > wrote: > > Is there any reasons/difficulties for not implementing named > > parameters? > > > > There is clearly a need: > > > > > http://forum.dlang.org/thread/wokfqqbexazcguffw...@forum.dlang.org#post-pxndhoskpjxvnoacajaz:40forum.dlang.org > > Function overloading and named arguments do not play well together, and we > have function overloading, so we're not going to have named arguments. > Walter made that clear at dconf. Now, as Idan pointed out in his reply, > work > has been done implement them via a library solution for those that want to, > so you might get something there, but not in the language itself. > > - Jonathan M Davis > >
Re: Why is there no named parameter support?
On Monday, June 08, 2015 20:36:05 Yuxuan Shui via Digitalmars-d-learn wrote: > Is there any reasons/difficulties for not implementing named > parameters? > > There is clearly a need: > > http://forum.dlang.org/thread/wokfqqbexazcguffw...@forum.dlang.org#post-pxndhoskpjxvnoacajaz:40forum.dlang.org Function overloading and named arguments do not play well together, and we have function overloading, so we're not going to have named arguments. Walter made that clear at dconf. Now, as Idan pointed out in his reply, work has been done implement them via a library solution for those that want to, so you might get something there, but not in the language itself. - Jonathan M Davis
Re: exclude current directory from search path in dmd ?
On Tuesday, 9 June 2015 at 00:22:09 UTC, Timothee Cour wrote: On Mon, Jun 8, 2015 at 12:08 AM, Adam D. Ruppe via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: The easiest way is to not use search paths, and instead pass all the modules you want compiled to the compiler directly. Then it will look for the module name declaration instead of the directory/filename layout. Could you be more specific, perhaps with a command line example? If I understand correctly, what you suggest doesn't bode well with separate compilation. Really, I think the easiest would be a flag to disable including current directory implicitly in search path dmd main.d ..\foo.d this will use base\foo.d dmd won't know base\bar\foo.d exists.
Re: Why is there no named parameter support?
On Monday, 8 June 2015 at 20:36:10 UTC, Yuxuan Shui wrote: Is there any reasons/difficulties for not implementing named parameters? There is clearly a need: http://forum.dlang.org/thread/wokfqqbexazcguffw...@forum.dlang.org#post-pxndhoskpjxvnoacajaz:40forum.dlang.org http://forum.dlang.org/thread/hdxnptcikgojdkmld...@forum.dlang.org
Re: exclude current directory from search path in dmd ?
On Mon, Jun 8, 2015 at 12:08 AM, Adam D. Ruppe via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > The easiest way is to not use search paths, and instead pass all the > modules you want compiled to the compiler directly. Then it will look for > the module name declaration instead of the directory/filename layout. > Could you be more specific, perhaps with a command line example? If I understand correctly, what you suggest doesn't bode well with separate compilation. Really, I think the easiest would be a flag to disable including current directory implicitly in search path
Re: Utf8 to Utf32 cast cost
On Monday, 8 June 2015 at 18:48:17 UTC, Daniel Kozak wrote: Yep, but I dont care, I am the one who makes transcode faster, so I am happy with results :P. P.S. I care and probably when I have some spare time I will improve to!dstring too Ah, so you are. I confused you with Kadir Erdem Demir.
Why is there no named parameter support?
Is there any reasons/difficulties for not implementing named parameters? There is clearly a need: http://forum.dlang.org/thread/wokfqqbexazcguffw...@forum.dlang.org#post-pxndhoskpjxvnoacajaz:40forum.dlang.org
Re: using D without GC
On Monday, 8 June 2015 at 13:37:40 UTC, Marc Schütz wrote: On Monday, 8 June 2015 at 12:24:56 UTC, Oleg B wrote: I guess you should follow andrei's post about new allocators! Can you get link to this post? These are some of his posts: http://forum.dlang.org/thread/mku0n4$s35$1...@digitalmars.com http://forum.dlang.org/thread/mkl1eh$1mdl$2...@digitalmars.com http://forum.dlang.org/thread/mjig8h$2rgi$1...@digitalmars.com http://forum.dlang.org/thread/mjdcep$11ri$1...@digitalmars.com http://forum.dlang.org/thread/mj3p2j$2qva$1...@digitalmars.com http://forum.dlang.org/thread/mir0lg$2l74$1...@digitalmars.com http://forum.dlang.org/thread/min9k8$9r9$1...@digitalmars.com Thank! Can you say how long wait (on average) to experimental modules will cease be an experimental and will be part of phobos? At next release or it unknown?
Re: Utf8 to Utf32 cast cost
On Mon, 08 Jun 2015 18:16:57 + Anonymouse via Digitalmars-d-learn wrote: > On Monday, 8 June 2015 at 11:44:47 UTC, Daniel Kozák wrote: > > No difference even with GC.disable() results are same. > > Profile! Callgrind is your friend~ Yep, but I dont care, I am the one who makes transcode faster, so I am happy with results :P. P.S. I care and probably when I have some spare time I will improve to!dstring too
Re: Utf8 to Utf32 cast cost
On Monday, 8 June 2015 at 11:44:47 UTC, Daniel Kozák wrote: No difference even with GC.disable() results are same. Profile! Callgrind is your friend~
Re: Error execute MS function fputc()
I found the solution. A problem in different structures of FILE for MSVC and DMC. I take the pointer on structure of FILE from CrtDLL.dll Everything works! // MGW 07.05.15 import core.runtime; // Загрузка DLL Для Win import std.stdio;// writeln version(Windows) { import std.c.windows.windows; // GetProcAddress для Windows } alias extern (C) int function(int, FILE*) t_fputc; t_fputc ms_fputc; int main(string[] args) { version(Windows) {auto libCrtDll = "CrtDll.dll"; } // Load CrtDLL.DLL MS Windows auto h = Runtime.loadLibrary(libCrtDll); // Find function fputc ms_fputc = cast(t_fputc)GetProcAddress(h, "fputc"); // Find array struct FILE MS void* ubuf = cast(void*)GetProcAddress(h, "_iob"); import core.stdc.stdio: stdout; try { // stdout --> FILE dmc auto rez = ms_fputc('A' , core.stdc.stdio.stdout); } catch { writeln("Error execute MS function fputc();"); } try { // cast(FILE*)(ubuf + 0) ==> stdin MSVC // cast(FILE*)(ubuf + 32) ==> stdout MSVC // stdout --> FILE MSVC auto rez = ms_fputc('B' , cast(FILE*)(ubuf + 32)); } catch { writeln("Error execute MS function ms_fputc();"); } return 0; }
Re: string to char array?
On Monday, 8 June 2015 at 09:54:28 UTC, Kagamin wrote: On Sunday, 7 June 2015 at 17:41:11 UTC, Kyoji Klyden wrote: Do you perchance have any links to learning resources for the D runtime(aside from just the github repository), and also maybe x86 architecture stuff? (I know intel has some 1000+ page pdf on their site, but I think that's more for hardware and/or OS designers..) Well, instruction reference is all you need: http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2008/10/24594_APM_v3.pdf Awesome, this is exactly what I was looking for! Thanks!
Re: How to remove the key from the `redBlackTree` with comparator" a <= b "?
On 6/8/15 6:53 AM, "Per =?UTF-8?B?Tm9yZGzDtnci?= " wrote: On Sunday, 7 June 2015 at 18:50:47 UTC, anonymous wrote: Do not use '<=' as a comparison function with RedBlackTree. It doesn't meet the requirements. Quoting the documentation [1]: Note that less should produce a strict ordering. That is, for two unequal elements a and b, less(a, b) == !less(b, a). less(a, a) should always equal false. This doesn't hold for '<='. Could we add a static check for this? How would a static check generate a and b generically? -Steve
Re: Error execute MS function fputc()
On 6/7/15 12:41 PM, MGW wrote: Hi, everybody! DMD32 D Compiler v2.067.0 I try to cause the fputc function from CrtDLL.DLL and I receive a mistake. Why? import core.runtime; // Загрузка DLL Для Win import std.stdio;// writeln version(Windows) { import std.c.windows.windows; // GetProcAddress для Windows } alias extern (C) int function(int, FILE*) t_fputc; t_fputc ms_fputc; int main(string[] args) { version(Windows) {auto libCrtDll = "CrtDll.dll"; } // Load CrtDLL.DLL MS Windows auto h = Runtime.loadLibrary(libCrtDll); // Find function fputc ms_fputc = cast(t_fputc)GetProcAddress(h, "fputc"); import core.stdc.stdio: stdout; try { auto rez = ms_fputc('A' , core.stdc.stdio.stdout); } catch { writeln("Error execute MS function fputc();"); } return 0; } DMD 32-bit does not use MSVC runtime, it uses DMC (Digital Mars C++ Compiler) runtime. So you cannot use MSVC versions of C runtime. You can use Win32 system calls, though. -Steve
Re: using D without GC
On Monday, 8 June 2015 at 12:24:56 UTC, Oleg B wrote: I guess you should follow andrei's post about new allocators! Can you get link to this post? These are some of his posts: http://forum.dlang.org/thread/mku0n4$s35$1...@digitalmars.com http://forum.dlang.org/thread/mkl1eh$1mdl$2...@digitalmars.com http://forum.dlang.org/thread/mjig8h$2rgi$1...@digitalmars.com http://forum.dlang.org/thread/mjdcep$11ri$1...@digitalmars.com http://forum.dlang.org/thread/mj3p2j$2qva$1...@digitalmars.com http://forum.dlang.org/thread/mir0lg$2l74$1...@digitalmars.com http://forum.dlang.org/thread/min9k8$9r9$1...@digitalmars.com
Re: using D without GC
I guess you should follow andrei's post about new allocators! Did you mean this article http://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation ?
Re: using D without GC
I guess you should follow andrei's post about new allocators! Can you get link to this post?
Re: Utf8 to Utf32 cast cost
On Mon, 08 Jun 2015 11:32:07 + Kagamin via Digitalmars-d-learn wrote: > On Monday, 8 June 2015 at 10:59:45 UTC, Daniel Kozák wrote: > > import std.conv; > > import std.utf; > > import std.datetime; > > import std.stdio; > > > > void f0() { > > string somestr = "some not so long utf8 string > > forbenchmarking"; > > dstring str = to!dstring(somestr); > > } > > > > > > void f1() { > > string somestr = "some not so long utf8 string > > forbenchmarking"; > > dstring str = toUTF32(somestr); > > } > > > > void main() { > > auto r = benchmark!(f0,f1)(1_000_000); > > auto f0Result = to!Duration(r[0]); > > auto f1Result = to!Duration(r[1]); > > writeln("f0 time: ",f0Result); > > writeln("f1 time: ",f1Result); > > } > > > > > > /// output /// > > f0 time: 2 secs, 281 ms, 933 μs, and 8 hnsecs > > f1 time: 600 ms, 979 μs, and 8 hnsecs > > Chances are you're benchmarking the GC. Try > benchmark!(f0,f1,f0,f1,f0,f1); No difference even with GC.disable() results are same.
Re: Utf8 to Utf32 cast cost
On Monday, 8 June 2015 at 10:59:45 UTC, Daniel Kozák wrote: import std.conv; import std.utf; import std.datetime; import std.stdio; void f0() { string somestr = "some not so long utf8 string forbenchmarking"; dstring str = to!dstring(somestr); } void f1() { string somestr = "some not so long utf8 string forbenchmarking"; dstring str = toUTF32(somestr); } void main() { auto r = benchmark!(f0,f1)(1_000_000); auto f0Result = to!Duration(r[0]); auto f1Result = to!Duration(r[1]); writeln("f0 time: ",f0Result); writeln("f1 time: ",f1Result); } /// output /// f0 time: 2 secs, 281 ms, 933 μs, and 8 hnsecs f1 time: 600 ms, 979 μs, and 8 hnsecs Chances are you're benchmarking the GC. Try benchmark!(f0,f1,f0,f1,f0,f1);
Re: Utf8 to Utf32 cast cost
On Monday, 8 June 2015 at 11:06:07 UTC, Daniel Kozák wrote: On Mon, 08 Jun 2015 10:51:53 + weaselcat via Digitalmars-d-learn wrote: On Monday, 8 June 2015 at 10:49:59 UTC, Ilya Yaroshenko wrote: > On Monday, 8 June 2015 at 10:42:00 UTC, Kadir Erdem Demir > wrote: >> I want to use my char array with awesome, cool >> std.algorithm functions. Since many of this algorithms >> requires like slicing etc.. I prefer to create my string >> with Utf32 chars. But by default all strings literals are >> Utf8 for performance. >> >> With my current knowledge I use to!dhar to convert >> Utf8[](or char[]) to Utf32[](or dchar[]) >> >> dchar[] range = to!dchar("erdem".dup) >> >> How costly is this? >> Is there a way which I can have Utf32 string directly >> without a cast? > > 1. dstring range = to!dstring("erdem"); //without dup > 2. dchar[] range = to!(dchar[])("erdem"); //mutable > 3. dstring range = "erdem"d; //directly > 4. dchar[] range = "erdem"d.dup; //mutable what's wrong with http://dlang.org/phobos/std_utf.html#.toUTF32 from: http://dlang.org/phobos/std_encoding.html#.transcode Supersedes: This function supersedes std.utf.toUTF8(), std.utf.toUTF16() and std.utf.toUTF32() (but note that to!() supersedes it more conveniently). BTW on ldc(ldc -O3 -singleobj -release -boundscheck=off) transcode is the fastest: f0 time: 1 sec, 115 ms, 48 μs, and 7 hnsecs // to!dstring f1 time: 449 ms and 329 μs // toUTF32 f2 time: 272 ms, 969 μs, and 1 hnsec // transcode
Re: Utf8 to Utf32 cast cost
On Mon, 08 Jun 2015 10:51:53 + weaselcat via Digitalmars-d-learn wrote: > On Monday, 8 June 2015 at 10:49:59 UTC, Ilya Yaroshenko wrote: > > On Monday, 8 June 2015 at 10:42:00 UTC, Kadir Erdem Demir wrote: > >> I want to use my char array with awesome, cool std.algorithm > >> functions. Since many of this algorithms requires like slicing > >> etc.. I prefer to create my string with Utf32 chars. But by > >> default all strings literals are Utf8 for performance. > >> > >> With my current knowledge I use to!dhar to convert Utf8[](or > >> char[]) to Utf32[](or dchar[]) > >> > >> dchar[] range = to!dchar("erdem".dup) > >> > >> How costly is this? > >> Is there a way which I can have Utf32 string directly without > >> a cast? > > > > 1. dstring range = to!dstring("erdem"); //without dup > > 2. dchar[] range = to!(dchar[])("erdem"); //mutable > > 3. dstring range = "erdem"d; //directly > > 4. dchar[] range = "erdem"d.dup; //mutable > > what's wrong with http://dlang.org/phobos/std_utf.html#.toUTF32 from: http://dlang.org/phobos/std_encoding.html#.transcode Supersedes: This function supersedes std.utf.toUTF8(), std.utf.toUTF16() and std.utf.toUTF32() (but note that to!() supersedes it more conveniently).
Re: Utf8 to Utf32 cast cost
Thanks a lot, your answers are very useful for me . Nothing wrong with toUtf32, I just didn't know it.
Re: Utf8 to Utf32 cast cost
On Mon, 08 Jun 2015 10:41:59 + Kadir Erdem Demir via Digitalmars-d-learn wrote: > I want to use my char array with awesome, cool std.algorithm > functions. Since many of this algorithms requires like slicing > etc.. I prefer to create my string with Utf32 chars. But by > default all strings literals are Utf8 for performance. > > With my current knowledge I use to!dhar to convert Utf8[](or > char[]) to Utf32[](or dchar[]) > > dchar[] range = to!dchar("erdem".dup) > > How costly is this? import std.conv; import std.utf; import std.datetime; import std.stdio; void f0() { string somestr = "some not so long utf8 string forbenchmarking"; dstring str = to!dstring(somestr); } void f1() { string somestr = "some not so long utf8 string forbenchmarking"; dstring str = toUTF32(somestr); } void main() { auto r = benchmark!(f0,f1)(1_000_000); auto f0Result = to!Duration(r[0]); auto f1Result = to!Duration(r[1]); writeln("f0 time: ",f0Result); writeln("f1 time: ",f1Result); } /// output /// f0 time: 2 secs, 281 ms, 933 μs, and 8 hnsecs f1 time: 600 ms, 979 μs, and 8 hnsecs
Re: How to remove the key from the `redBlackTree` with comparator" a <= b "?
On Sunday, 7 June 2015 at 18:50:47 UTC, anonymous wrote: Do not use '<=' as a comparison function with RedBlackTree. It doesn't meet the requirements. Quoting the documentation [1]: Note that less should produce a strict ordering. That is, for two unequal elements a and b, less(a, b) == !less(b, a). less(a, a) should always equal false. This doesn't hold for '<='. Could we add a static check for this?
Re: Utf8 to Utf32 cast cost
On Monday, 8 June 2015 at 10:49:59 UTC, Ilya Yaroshenko wrote: On Monday, 8 June 2015 at 10:42:00 UTC, Kadir Erdem Demir wrote: I want to use my char array with awesome, cool std.algorithm functions. Since many of this algorithms requires like slicing etc.. I prefer to create my string with Utf32 chars. But by default all strings literals are Utf8 for performance. With my current knowledge I use to!dhar to convert Utf8[](or char[]) to Utf32[](or dchar[]) dchar[] range = to!dchar("erdem".dup) How costly is this? Is there a way which I can have Utf32 string directly without a cast? 1. dstring range = to!dstring("erdem"); //without dup 2. dchar[] range = to!(dchar[])("erdem"); //mutable 3. dstring range = "erdem"d; //directly 4. dchar[] range = "erdem"d.dup; //mutable what's wrong with http://dlang.org/phobos/std_utf.html#.toUTF32
Re: Utf8 to Utf32 cast cost
On Mon, 08 Jun 2015 10:41:59 + Kadir Erdem Demir via Digitalmars-d-learn wrote: > I want to use my char array with awesome, cool std.algorithm > functions. Since many of this algorithms requires like slicing > etc.. I prefer to create my string with Utf32 chars. But by > default all strings literals are Utf8 for performance. > > With my current knowledge I use to!dhar to convert Utf8[](or > char[]) to Utf32[](or dchar[]) > > dchar[] range = to!dchar("erdem".dup) > > How costly is this? > Is there a way which I can have Utf32 string directly without a > cast? dstring str = "erdem"d; dstring str2 = std.utf.toUTF32(someUtf8Or16Or32String);
Re: Utf8 to Utf32 cast cost
On Monday, 8 June 2015 at 10:42:00 UTC, Kadir Erdem Demir wrote: I want to use my char array with awesome, cool std.algorithm functions. Since many of this algorithms requires like slicing etc.. I prefer to create my string with Utf32 chars. But by default all strings literals are Utf8 for performance. With my current knowledge I use to!dhar to convert Utf8[](or char[]) to Utf32[](or dchar[]) dchar[] range = to!dchar("erdem".dup) How costly is this? Is there a way which I can have Utf32 string directly without a cast? 1. dstring range = to!dstring("erdem"); //without dup 2. dchar[] range = to!(dchar[])("erdem"); //mutable 3. dstring range = "erdem"d; //directly 4. dchar[] range = "erdem"d.dup; //mutable
Utf8 to Utf32 cast cost
I want to use my char array with awesome, cool std.algorithm functions. Since many of this algorithms requires like slicing etc.. I prefer to create my string with Utf32 chars. But by default all strings literals are Utf8 for performance. With my current knowledge I use to!dhar to convert Utf8[](or char[]) to Utf32[](or dchar[]) dchar[] range = to!dchar("erdem".dup) How costly is this? Is there a way which I can have Utf32 string directly without a cast?
Re: using D without GC
On Sunday, 7 June 2015 at 16:25:29 UTC, Oleg B wrote: No just reserve some memory and preallocate the buffer you want before using it. It'll be a lot faster and cheaper. I know, it's only for test. You shouldn't be using delete or new for that matter. You should be using malloc + free. And emplace. auto myalloc(T)( size_t count ) { struct Impl{ size_t len; void* ptr; } union Wrap { Impl impl; T[] arr; } auto ret = Wrap( Impl( count, calloc( count, T.sizeof ) ) ).arr; enforce( ret.ptr !is null ); return ret; } class Bar { float[] buf; this() { buf = myalloc!float( 65536 ); } ~this() { free(buf.ptr); } } For simple types arrays all clear. Emplace realization not trivial for me yet. As I understand correctly it concerns placing initial values of struct for example or values before calling ctor in place to array segment without copying? But what I need use for class objects? class Foo { Bar[] buf; this() { buf = myalloc!Bar( 100 ); // I think it's ok foreach( ref b; buf ) b = new Bar; // but calloc can't initialize class correctly } ~this() { static if( gc_disable ) { foreach( ref b; buf ) delete b; free(buf.ptr); } } } Operator new automatically allocate range in GC-manage memory? If it is whether is possible to change this behavior? It's question relates to emplace too? I guess you should follow andrei's post about new allocators!
Re: string to char array?
On Sunday, 7 June 2015 at 17:41:11 UTC, Kyoji Klyden wrote: Do you perchance have any links to learning resources for the D runtime(aside from just the github repository), and also maybe x86 architecture stuff? (I know intel has some 1000+ page pdf on their site, but I think that's more for hardware and/or OS designers..) Well, instruction reference is all you need: http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2008/10/24594_APM_v3.pdf
Re: using D without GC
On Sunday, 7 June 2015 at 10:16:36 UTC, Oleg B wrote: Hello. I want to try use D without GC and I'm not sure what I do all right. You may want to take a look at this Wiki page. It has several patterns managing memory without the GC: http://wiki.dlang.org/Memory_Management Mike
Re: DFL background tasks
On Monday, 8 June 2015 at 07:45:28 UTC, Ali Çehreli wrote: > receiveTimeout(dur!"msecs"(0). UFCS makes durations more pleasant: :) receiveTimeout(0.msecs) Oh, thanks! I missed this bit. This is much nicer!
Re: DFL background tasks
Just a couple of minor improvements: On 06/08/2015 12:22 AM, thedeemon wrote: > spawn() a thread and don't pass any GUI controls to it, just > thisTid (identifier of your main UI thread) The owner's thread id is available as 'ownerTid' as well. > receiveTimeout(dur!"msecs"(0). UFCS makes durations more pleasant: :) receiveTimeout(0.msecs) Ali
Re: DFL background tasks
A more general and proper approach is to use message passing from std.concurrency. With DFL it looks like this: you spawn() a thread and don't pass any GUI controls to it, just thisTid (identifier of your main UI thread). In that worker tread when you've got some data to show in the UI (be it end result of just some status update) you use tid.send(...) and send the data in appropriate messages (defined as separate structs or classes). In the main UI thread you've got a Timer running that checks whether there are any messages in the main thread's mailbox and process them there. Here's an example from a real DFL project: https://bitbucket.org/infognition/undup/src/e8d295b89bc76545860e38a8c9ee171c86f3c84c/newscan.d?at=default#cl-200 OnStart() is a button callback. It does some quick UI updates and spawns a thread, passing relevant data and thisTid: worker = spawn(&makeScan, fname, hdr, thisTid); (makeScan is a function with some long running operation, it's defined in another module) There is also a timer set up when a form is created, and in the timer function OnTimer() there is a check for new messages via receiveTimeout(dur!"msecs"(0). while(receiveTimeout(dur!"msecs"(0), &RcvMsgNumOfDirs, &RcvMsgScanning, &RcvMsgDone)) {} Important part here is to make it non-blocking, it should not sit here waiting for new messages, otherwise UI will not be responsive. And RcvMsgNumOfDirs, RcvMsgScanning, RcvMsgDone are functions that react to corresponding messages sent from the worker thread. They work in the UI thread, of course.
Re: DFL background tasks
On Sunday, 7 June 2015 at 13:34:59 UTC, Scroph wrote: I tried your code and it did work, however it still froze the UI while it was retrieving the data. Sure, because now you do your long operation in the UI thread. What happens in the delegate passed to invoke() happens in the main UI thread. You've got two steps: first some long operation producing some data, then updating the listview with this data. You need to do the long processing part in a worker thread and updating in the UI thread. This is how it's done: in the button callback (which runs in UI thread) you spawn() a thread with some worker function. This worker function does your long operation, and it happens in separate thread so the UI keeps responding. After you finished this long operation you call listview.invoke() with a delegate that just updates the listview, it doesn't do any long operations. This update will happen in the UI thread. Something like: void loadDetailsCallback(Control sender, EventArgs ea) { ... spawn(&loadDetails, qualityBox); // quickly launch a thread // and go on responding to UI events } void loadDetails(ListView qualityBox) { //do the work, this happens in worker thread vid = ... qualityBox.invoke( { // this part happens in UI thread, quickly qualityBox.beginUpdate(); // this belongs out of loop foreach(q; vid.qualities) { qualityBox.addRow(q.itag.to!string, q.type, q.quality, q.link); } qualityBox.endUpdate(); }); }