Re: Capturing by value in the thread

2024-10-18 Thread mzfhhhh via Digitalmars-d-learn
On Friday, 18 October 2024 at 12:07:24 UTC, Kadir Erdem Demir wrote: It seems [=] functionality C++ does not exist in D. By using a helper function I made that example work. [...] Because 'work' is captured, it is allocated on the heap. The loops are all assigning values to this 'work' in the

Re: why the sort result is different with C#

2016-01-22 Thread mzfhhhh via Digitalmars-d-learn
i know the reason,C# have several compares methods. String.Compare , String.CompareOrdinal //now the output is same as the D code Array.Sort(arr, string.CompareOrdinal);

why the sort result is different with C#

2016-01-21 Thread mzfhhhh via Digitalmars-d-learn
D code: auto arr = ["b1=1", "b=2","a1=1", "a=2"]; writeln(arr.sort()); output:["a1=1", "a=2", "b1=1", "b=2"] C# code: var arr = new string[]{ "b1=1", "b=2", "a1=1", "a=2" }; Array.Sort(arr); output:["a=2","a1=1","b=2","b1=1"]

Re: pi program

2015-09-25 Thread mzfhhhh via Digitalmars-d-learn
If we worry about the string form and instead try: double reduce_string_loop() { return reduce!"1.0 / (a * a)"(iota(1, 100)); } double reduce_function_loop() { return reduce!((n) => 1.0 / (n * n))(iota(1, 100)); } it should be write : double reduce_loop() { //return iota(1, 100).map!"

Re: Chaining struct method invocations

2015-09-07 Thread mzfhhhh via Digitalmars-d-learn
On Monday, 7 September 2015 at 14:12:25 UTC, Bahman Movaqar wrote: I need some help understand the behaviour of my code[1]. Specifically I have trouble with `add` method on line 79. My impression is that since it returns `this`, multiple invocations can be chained like `obj.add(X).add(Y).add(

Re: What is the D way to map a binary file to a structure?

2015-08-30 Thread mzfhhhh via Digitalmars-d-learn
On Saturday, 29 August 2015 at 12:56:08 UTC, cym13 wrote: Hi, Let's say I have a simple binary file whose structure is well-known. Here is an example which stores points: struct Point { long x; long y; long z; } struct BinFile { uintmagicNumber; // Some identifier ul

why adding extern(C) cause a runtime error?

2015-07-10 Thread mzfhhhh via Digitalmars-d-learn
win7 x86 dmd2.067.1 ok ubuntu x64 dmd2.067.1 error - import std.stdio; import std.socket; extern(C) void recv() { writeln("recv..."); } extern(C) void send() { writeln("send..."); } int main(string[] argv) { //copy from std.socket unittest

build vibe-d-0.7.23 error on win7 x86?

2015-04-20 Thread mzfhhhh via Digitalmars-d-learn
win 7 x86,3GB ram: 1. dmd 2.066 vibe-d-0.7.23, it's ok. 2. dmd 2.067 vibe-d-0.7.23, show error msg "out of memory" why?

Re: how call a c function with stdcall?

2015-03-24 Thread mzfhhhh via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 00:26:21 UTC, Adam D. Ruppe wrote: On Wednesday, 25 March 2015 at 00:09:33 UTC, mzf wrote: i use "implib.exe /system func.lib func.dll" to create a func.lib. You might also need to specify the .def file as the final argument to that. http://digitalmars.com

Re: how call a c function with stdcall?

2015-03-24 Thread mzfhhhh via Digitalmars-d-learn
On Tuesday, 24 March 2015 at 15:26:22 UTC, Adam D. Ruppe wrote: try extern(Windows) isntead of extern(C). use extern(Windows) or extern(System) the compile show the link error: Error 42: Symbol Undefined _sub@8 dll export func name is "sub", and the dll is 3rd party,i can't c

how call a c function with stdcall?

2015-03-24 Thread mzfhhhh via Digitalmars-d-learn
for example:use vc compile on x86 func.c: __declspec(dllexport) int _stdcall sub(int a,int b) { return a-b; } func.def: LIBRARY EXPORTS sub - i use "implib.exe" to create a omf format lib. D code: import std.exception; //this is a cdecl call extern(C) i

Re: why GC not work?

2015-02-08 Thread mzfhhhh via Digitalmars-d-learn
On Saturday, 7 February 2015 at 06:08:39 UTC, ketmar wrote: On Sat, 07 Feb 2015 04:30:07 +, Safety0ff wrote: False pointers, current GC is not precise. not only that. constantly allocating big chunks of memory will inevitably lead to OOM due to current GC design. you can check it with m

Re: How to write asia characters on console?

2015-02-08 Thread mzfhhhh via Digitalmars-d-learn
Thanks, my problem has been solved:) --- import std.stdio; import core.stdc.wchar_; extern(C) int setlocale(int, char*); static this() { fwide(core.stdc.stdio.stdout, 1); setlocale(0, cast(char*)"china"); } int main(string[] args) { string s1 =

Re: why spawn crash?

2015-02-08 Thread mzfhhhh via Digitalmars-d-learn
On Saturday, 24 January 2015 at 01:54:32 UTC, mzf wrote: thanks,you are right. window console show chinese char is not right, so i try to add this code: " extern(C) int setlocale(int, char*); static this() { fwide(core.stdc.stdio.stdout, 1); setlocale(LC_CTYPE, cast(char*)"china"); }

why GC not work?

2015-02-06 Thread mzfhhhh via Digitalmars-d-learn
import std.stdio; void testGC() { auto b = new byte[](1024*1024*100); writeln("malloc 100M!"); } void main() { foreach(i;1..100) { testGC(); } } -- core.exception.OutOfMemoryError@(0) win7 x86,dmd v2.066.0

how convert the range to slice ?

2015-01-28 Thread mzfhhhh via Digitalmars-d-learn
is there any simple way to convert? int [] arr1 = [1,2,3].map!"a*2"; //compile error int [] arr2 = [1,2,3].filter!"a<3";//compile error

Re: why spawn crash?

2015-01-23 Thread mzfhhhh via Digitalmars-d-learn
thanks,you are right. window console show chinese char is not right, so i try to add this code: " extern(C) int setlocale(int, char*); static this() { fwide(core.stdc.stdio.stdout, 1); setlocale(LC_CTYPE, cast(char*)"china"); } " it's looks like solve the problem,but caused another proble

why spawn crash?

2015-01-22 Thread mzfhhhh via Digitalmars-d-learn
i wrote a test code: void worker(int firstNumber) { Thread.sleep(1.msecs); } void main() { foreach (i; 1 .. 1000) { spawn(&worker, i ); writeln(i); } thread_joinAll(); writeln("ok"); } sometimes it's ok,sometimes it's crashed ! why ? here is one of times ca