Re: Advice wanted on garbage collection of sockets for c++ programmer using D
On Tuesday, 27 June 2017 at 09:54:19 UTC, John Burton wrote: I'm coming from a C++ background so I'm not too used to garbage collection and it's implications. I have a function that creates a std.socket.Socket using new and connects to a tcp server, and writes some stuff to it. I then explicitly close the socket, and the socket object goes out of scope. [...] May be you can see yu: https://github.com/dushibaiyu/yu
Re: Garbage collection and closures.
On Monday, 19 June 2017 at 09:10:16 UTC, Dsby wrote: On Saturday, 17 June 2017 at 17:15:50 UTC, Adam D. Ruppe wrote: On Saturday, 17 June 2017 at 14:19:34 UTC, ANtlord wrote: [...] Where the variable is defined that is referenced in the closure. So: [...] if the uses parma is 'scope': void uses(scope void delegate() dg); will it be not alloc memory? I test it , if use scope it will not alloc memony. import std.stdio; void call(void delegate() fun) { fun(); } void call2(scope void delegate() fun) { fun(); } void main() { int a = 10; // call((){writeln(a);}); call2((){writeln(a);}); } dmd -vgc ./t.d it will not print anything. if use call: void main() { int a = 10; call((){writeln(a);}); // call2((){writeln(a);}); } dmd -vgc ./t.d 182ms 2017年06月19日 星期一 17时16分47秒 ./t.d(13): vgc: using closure causes GC allocation
Re: Garbage collection and closures.
On Saturday, 17 June 2017 at 17:15:50 UTC, Adam D. Ruppe wrote: On Saturday, 17 June 2017 at 14:19:34 UTC, ANtlord wrote: [...] Where the variable is defined that is referenced in the closure. So: [...] if the uses parma is 'scope': void uses(scope void delegate() dg); will it be not alloc memory?
Re: erro when use core.runtime
I am in openSUSE. I see the code in runtime. it is only support Windows in default. in posix only version (Shared) is will build. why?
Re: erro when use core.runtime
On Thursday, 18 May 2017 at 04:53:36 UTC, Dsby wrote: Linking... ../../.dub/build/library-debug-linux.posix-x86_64-dmd_2073-368A963AFD76168526BD99BBB313FD4B/libyu.a(runtime_a21_4e7.o):在函数‘_D4core7runtime7Runtime17__T11loadLibraryZ11loadLibraryFxAaZPv ’中: /usr/include/dmd/druntime/import/core/runtime.d:222:对‘rt_loadLibrary’未定义的引用 ../../.dub/build/library-debug-linux.posix-x86_64-dmd_2073-368A963AFD76168526BD99BBB313FD4B/libyu.a(runtime_a22_5ca.o):在函数‘_D4core7runtime7Runtime19__T13unloadLibraryZ13unloadLibraryFPv Zb’中: /usr/include/dmd/druntime/import/core/runtime.d:237:对‘rt_unloadLibrary’未定义的引用 it is in 2.073.1 it is also error in ldc 1.1.0 (dmd 2.071.2)
erro when use core.runtime
Linking... ../../.dub/build/library-debug-linux.posix-x86_64-dmd_2073-368A963AFD76168526BD99BBB313FD4B/libyu.a(runtime_a21_4e7.o):在函数‘_D4core7runtime7Runtime17__T11loadLibraryZ11loadLibraryFxAaZPv ’中: /usr/include/dmd/druntime/import/core/runtime.d:222:对‘rt_loadLibrary’未定义的引用 ../../.dub/build/library-debug-linux.posix-x86_64-dmd_2073-368A963AFD76168526BD99BBB313FD4B/libyu.a(runtime_a22_5ca.o):在函数‘_D4core7runtime7Runtime19__T13unloadLibraryZ13unloadLibraryFPv Zb’中: /usr/include/dmd/druntime/import/core/runtime.d:237:对‘rt_unloadLibrary’未定义的引用 it is in 2.073.1
Re: What is PostgreSQL driver is most stable?
On Tuesday, 14 March 2017 at 16:24:31 UTC, Paolo Invernizzi wrote: On Tuesday, 14 March 2017 at 13:32:31 UTC, Suliman wrote: On Tuesday, 14 March 2017 at 13:21:39 UTC, Paolo Invernizzi wrote: On Tuesday, 14 March 2017 at 13:13:31 UTC, Suliman wrote: [...] I'm using ddb [1], a full-D implementation of the PostgreSQL protocol. Not everything it's in place, but it does its works, and the codebase is pretty simple, so it's not difficult to contribute if you need to add some feature that's missing for your use case. [1] https://github.com/pszturmaj/ddb --- Paolo Does it work fine on Linux with x64 Postgres? Yes --- Paolo We used dpq. http://code.dlang.org/packages/dpq
Re: GC question
On Friday, 3 February 2017 at 11:36:26 UTC, osa1 wrote: On Friday, 3 February 2017 at 10:49:00 UTC, Kagamin wrote: Leaks are likely in 32-bit processes and unlikely in 64-bit processes. See e.g. https://issues.dlang.org/show_bug.cgi?id=15723 This looks pretty bad. I think I'll consider something else until D's memory management story gets better. This is sad because the language otherwise looks quite good, and I'd love to try assertions, contracts, scope guards, macros etc. you can use less auto GC. use the RC to replace the GC. https://github.com/huntlabs/SmartRef
Re: the best language I have ever met(?)
On Friday, 18 November 2016 at 17:54:52 UTC, Igor Shirkalin wrote: The simpler - the better. After reading "D p.l." by A.Alexandrescu two years ago I have found my past dream. It's theory to start with. That book should be read at least two times especially if you have asm/c/c++/python3/math/physics background, and dealt with Watcom/Symantec C/C++ compilers (best to Walter Bright) with very high optimization goal. No stupid questions, just doing things. That was preface. Now I have server written in D for C++ pretty ancient client. Most things are three times shorter in size and clear (@clear? suffix). All programming paradigms were used. I have the same text in russian, but who has bothered russian(s)? The meaning of all of that is: powerfull attractive language with sufficient infrastructure with future. Just use it. [...] My English is Bad than yours. I am mot russian(s)、、、I am Chinese.
Re: @safe fun alayws call @system function?
On Tuesday, 12 July 2016 at 09:17:37 UTC, ag0aep6g wrote: On 07/12/2016 11:09 AM, Dsby wrote: How can i call @system function in a @safe function? You can't. You can mark the @safe function @trusted [1] instead. @trusted functions are considered memory-safe by the compiler and can be called from @safe code, but they can use @system features and call @system functions. A @trusted function must still be memory-safe, and the compiler cannot check that it is, so you as the programmer take on the responsibility to ensure that the function is in fact memory-safe. Be very careful with @trusted and make sure you know exactly what you're doing. A bad @trusted function compromises the whole call chain. [1] https://dlang.org/spec/function.html#trusted-functions Thanks!
@safe fun alayws call @system function?
How can i call @system function in a @safe function?
Re: D equivalent of C++ bind ?
On Monday, 16 May 2016 at 15:11:26 UTC, chmike wrote: On Thursday, 12 May 2016 at 10:38:37 UTC, Dsby wrote: [...] Thank you. Would you agree to help me understand it ? The only thing I don't understand is why the function template argument is defined as T and the argument as auto ref T fun. Why the auto ref and not alias T in the template argument list ? This bind is better than Partial!() from std.functional since it accepts any number of parameters. But the given parameters are passed as first arguments of fun. The std::bind of C++ allows to bind any parameter in any order and eventually multiple times. It's really as if a new function was defined with a total liberty degree on its signature. Anyway thank you very much. you can remove "auto ref". and I remove the "auto ref" in my use. if used the "alias T", It can not handle all while when the T is a delegate. in C++ std::bind, the arguments order you can sort by used. in D I do not find how to enablement.
Re: Async or event library
On Tuesday, 10 May 2016 at 13:34:36 UTC, chmike wrote: vibed uses libevent, a C library. The discussion is regarding a possible pure D equivalent of libevent. libasync is an interesting proposal but it is apparently slower than libevent. I don't know the current status because vibed improved its performance in the last months. My initial question is if there is a working group I could join to work on this pure D async library. I'm interested in working on the subject. if you used in unix(linux,bsd,mac),you can look our's event-net lib. now it is only epoll(linux), the kqueue(bsd and mac) is easy to support. and now only timer and tcp. It's like facebook/wangle(Netty + Finagle) smooshed together, but in D. https://github.com/putao-dev/collie
Re: D equivalent of C++ bind ?
On Tuesday, 10 May 2016 at 15:33:03 UTC, chmike wrote: Thanks. This does the job but it's not as concise. The std.functional.partial can not use in runtime, only on complier time. and it can not bind args that more than one.
Re: D equivalent of C++ bind ?
On Tuesday, 10 May 2016 at 09:39:53 UTC, chmike wrote: Is there an equivalent in D of the C++11 std.bind template class [http://en.cppreference.com/w/cpp/utility/functional/bind] ? Here is a blog post showing different examples of its use https://oopscenities.net/2012/02/24/c11-stdfunction-and-stdbind/ A possible use case is for a callback function/delegate with the expected signature bool cb(int error). I would like to pass a function bool myCb(int error, ref int myArg) instead with the variable myArg being given as predefined argument. Here is an example. int count = 0; bool myCb(int error, ref int myArg) { if (myArg >= 6) return false; writeln(++myArg); return true; } void async_task(void function(int error) cb) { . . . while cb(0) . . . } void main() { . . . async_task( ??? myCb ??? count ??? ); . . . } In C++ we would write async_task(std::bind(myCb, std::placeholders::_1, count)); I write one, bind functon to a delegate. In here: https://github.com/putao-dev/collie/blob/master/source/collie/utils/functional.d this is the code: auto bind(T,Args...)(auto ref T fun,Args args) if (isCallable!(T)) { alias FUNTYPE = Parameters!(fun); static if(is(Args == void)) { static if(isDelegate!T) return fun; else return toDelegate(fun); } else static if(FUNTYPE.length > args.length) { alias DTYPE = FUNTYPE[args.length..$]; return delegate(DTYPE ars){ TypeTuple!(FUNTYPE) value; value[0..args.length] = args[]; value[args.length..$] = ars[]; return fun(value); }; } else { return delegate(){return fun(args);}; } }
Re: Async or event library
On Thursday, 5 May 2016 at 08:19:26 UTC, chmike wrote: Hello I have seen the wiki page https://wiki.dlang.org/Event_system and would like to know the current status. Is there a working group for this subject ? This is a topic I'm interested in and did some modest work on some years ago. [...] We has one: Collie, now is in develop, and use in our server. Use for TCP and http. It like facebook/wangle: https://github.com/putao-dev/collie
How can I save a class use the RedBlackTree?
this is the test Code: import std.container.rbtree; import std.stdio; class TClass { int i; } void main() { RedBlackTree!(TClass) list = new RedBlackTree!(TClass)(); auto t = new TClass(); list.insert(t); writeln("The rbtree length is ",list.length()); list.removeKey(t); writeln("The rbtree length is ",list.length()); } and thisis erro : /usr/include/dlang/dmd-2.071.0/phobos/std/functional.d-mixin-206(206): Error: mutable method object.Object.opCmp is not callable using a inout object /usr/include/dlang/dmd-2.071.0/phobos/std/container/rbtree.d(871): Error: template instance std.functional.binaryFun!("a < b", "a", "b").binaryFun!(inout(TClass), TClass) error instantiating rbtree.d(11):instantiated from here: RedBlackTree!(TClass, "a < b", false) /usr/include/dlang/dmd-2.071.0/phobos/std/functional.d-mixin-206(206): Error: function object.Object.opCmp (Object o) is not callable using argument types (inout(TClass)) /usr/include/dlang/dmd-2.071.0/phobos/std/container/rbtree.d(873): Error: template instance std.functional.binaryFun!("a < b", "a", "b").binaryFun!(TClass, inout(TClass)) error instantiating rbtree.d(11):instantiated from here: RedBlackTree!(TClass, "a < b", false)
std.signals Can not connect a delegate without in Object
import std.signals; import std.stdio; class hh { mixin Signal!(); void haha(){emit();} } class ff { void show() { writeln("ff show"); } } void main() { auto h = new hh(); void show() { writeln("main show"); } auto f = new ff(); // h.connect(); // It is ok to work h.connect(); // will Segmentation fault 。 h.haha(); }
Re: Whitch can replace std::bind/boost::bind ?
On Friday, 18 March 2016 at 17:24:27 UTC, Ali Çehreli wrote: On 03/18/2016 03:50 AM, Dsby wrote: foreach (i ; 0..4) { auto th = new Thread(delegate(){listRun(i);});//this is erro _thread[i]= th; th.start(); } void listRun(int i) { writeln("i = ", i); // the value is not(0,1,2,3), it all is 2. } I want to know how to use it like std::bind. A workaround is an intermediate function that returns the delegate: import std.stdio; import core.thread; void listRun(int i) { writeln("i = ", i); // the value is not(0,1,2,3), it all is 2. } auto makeClosure(int i) { return delegate(){listRun(i);}; } void main() { Thread[4] _thread; foreach (i ; 0..4) { auto th = new Thread(makeClosure(i)); _thread[i]= th; th.start(); } } Prints different values: i = 1 i = 0 i = 2 i = 3 Ali Thanks for your mind. i write the bind function: import std.stdio; import core.thread; import std.functional; class AA { void show(int i) { writeln("i = ", i); // the value is not(0,1,2,3), it all is 2. } } void listRun(int i) { writeln("i = ", i); } void main() { Thread[4] _thread; Thread[4] _thread2; AA a = new AA(); foreach (i ; 0..4) { auto th = new Thread(bindDg(,i)); _thread[i]= th; auto th2 = new Thread(bindFun!listRun(i + 10)); _thread2[i]= th2; } foreach(i;0..4) { _thread[i].start(); } foreach(i;0..4) { _thread2[i].start(); } } auto bindDg(T, Args...)(T fun,Args args) if (is(T == delegate) || is(T == function)) { return delegate(){return fun(forward!args);}; } auto bindFun(alias Fun,Args...)(Args args) { return delegate(){return Fun(forward!args);}; } my value is : i = 2 i = 0 i = 3 i = 11 i = 13 i = 10 i = 12 i = 1
Re: How about use Gc as a big memory pool?
On Friday, 8 April 2016 at 05:31:10 UTC, Olivier Pisano wrote: On Friday, 8 April 2016 at 03:27:04 UTC, Dsby wrote: when the soft start, call GC.disable(). use "new " create a class , struct or a array. and use destory(T/void *) to call the ~this(), then GC.free to free the memory, and use RAII in class or Struct. And user the Timer, or in some where to call : GC.enable(), GC.collect(), GC.disable(); In this way , i can know and control when is GC runing. Is This way feasible? will It have a problem? It should work, but you cannot predict how much time collect() will take, since it depends on the system state (how much work it has to do). So instead of calling it at fixed intervals, you'd better call it when your application is idle. Why don't you try to use https://dlang.org/phobos/std_experimental_allocator.html ? It work. before 2.071, in the ~this call GC.free will Erro. now it is fine. I know and used experimental_allocator. but new is better than theAllocator.make!(), in read, and write.
How about use Gc as a big memory pool?
when the soft start, call GC.disable(). use "new " create a class , struct or a array. and use destory(T/void *) to call the ~this(), then GC.free to free the memory, and use RAII in class or Struct. And user the Timer, or in some where to call : GC.enable(), GC.collect(), GC.disable(); In this way , i can know and control when is GC runing. Is This way feasible? will It have a problem?
Can i get a array Slicing where the top from?and how?
Like this: ubyte[] fun() { ubyte[] str = cast(ubyte[])"hello world"; ubyte[] by = Mallocator.instance.allocate(str.length); by[] = str[]; return by[5..$]; } void mian() { ubyte[] aa = fun(); // i want free the aa's momeny. //Mallocator.instance.deallocate(aa);// it is erro, aa.ptr != by.ptr? // can I get the by's ptr and length? } can I get "by" in main function by aa? i can get the way?is it possible ?
Re: Whitch can replace std::bind/boost::bind ?
On Friday, 18 March 2016 at 11:09:37 UTC, Atila Neves wrote: On Friday, 18 March 2016 at 10:50:34 UTC, Dsby wrote: foreach (i ; 0..4) { auto th = new Thread(delegate(){listRun(i);});//this is erro _thread[i]= th; th.start(); } void listRun(int i) { writeln("i = ", i); // the value is not(0,1,2,3), it all is 2. } I want to know how to use it like std::bind. I would suggest not using Thread directly: foreach(i; 0..4) { auto tid = spawn(, i); //from std.concurrency _tid[i] = tid; } Atila the listrun is in class. it is a delegate,it is not a function.
Whitch can replace std::bind/boost::bind ?
foreach (i ; 0..4) { auto th = new Thread(delegate(){listRun(i);});//this is erro _thread[i]= th; th.start(); } void listRun(int i) { writeln("i = ", i); // the value is not(0,1,2,3), it all is 2. } I want to know how to use it like std::bind.
Re: is module ( std.experimental.logger) thread-safe.
On Thursday, 10 March 2016 at 23:56:14 UTC, ZombineDev wrote: On Sunday, 6 March 2016 at 09:54:49 UTC, Dsby wrote: I want to use the filelogger to my application. is the sharedLog() global and thread-safe. Yes, `FileLogger` internally uses `lockingTextWriter`, so it should be safe to call from multiple threads. Furthermore, the `sharedLog` property uses atomic load and store instructions, so it should be OK to concurrently change the shared logger. Thanks. I was test and used in my mutil-threads application. It works fine.
is module ( std.experimental.logger) thread-safe.
I want to use the filelogger to my application. is the sharedLog() global and thread-safe.
Use the D dylib in my C++ program,when the D's GC(in the dylib runtime) run. will not my program stop?
Use the D dylib in my C++ program,when the D's GC(in the dylib runtime) run. will not my program stop? My lib.so is writed in D, and I use the GC.and then I am used the dll in my program that is writed in C++. I want to know when the GC(in lib.so's runtime) start runing, will my program be stoped,until the GC stop? sorry , my english is bad. I will use chinese to describe this question: 我用D语言写了一个的动态库,其中里面的内存分配和回收用的是GC。现在我的C++程序去调用这个动态库。我想知道,当动态库所依赖的的D的运行时中GC运行的时候,是不是我的整个程序都会暂停住,知道GC回收完毕再次唤醒?
Re: Use the D dylib in my C++ program,when the D's GC(in the dylib runtime) run. will not my program stop?
On Saturday, 30 January 2016 at 16:06:37 UTC, Chris Wright wrote: On Sat, 30 Jan 2016 14:41:18 +, Dsby wrote: Use the D dylib in my C++ program,when the D's GC(in the dylib runtime) run. will not my program stop? The GC will stop every thread it knows about. If you have a C++ thread that you want to run while the GC is running, you can get that by not telling the D runtime about it. This will limit your ability to interact with D from that thread somewhat -- and it will interfere more with your ability to *safely* interact with D even more. If you never allocate GC memory, of course, the GC will never run. Thanks, if I use the D dylib,I should run " rt_init(); " in every thread which i used the D dylib?
Re: Use the D dylib in my C++ program,when the D's GC(in the dylib runtime) run. will not my program stop?
On Sunday, 31 January 2016 at 05:29:06 UTC, Mike Parker wrote: On Sunday, 31 January 2016 at 05:28:02 UTC, Mike Parker wrote: need to call core.thread.attach_this [1] so that runtime is Sorry, that's core.thread.thread_attachThis ok。thanks.
Why is it a memory ERRO.
the Code: class MyClass { this(){ by = new ubyte[1]; ++i; } ~this(){ GC.free(by.ptr); by = null; writeln("free"); } void show(){ writeln(i); }; private: ubyte[] by; static i = 0; }; void main() { bool start = true; int i = 0; while(start){ auto obj = new MyClass(); obj.show(); Thread.sleep(5.msecs); //obj.destroy; //GC.free(cast(void *)obj); ++i; if (i > 2) break; } } the code will be : 341 core.exception.InvalidMemoryOperationError@src/core/exception.d(679): Invalid memory operation core.exception.InvalidMemoryOperationError@src/core/exception.d(679): Invalid memory operation .why is it? if < obj.destroy; > is exec. the code will not errno.
Re: Why is it a memory ERRO.
On Friday, 29 January 2016 at 12:43:53 UTC, Dsby wrote: the Code: class MyClass { this(){ by = new ubyte[1]; ++i; } ~this(){ GC.free(by.ptr); by = null; writeln("free"); } void show(){ writeln(i); }; private: ubyte[] by; static i = 0; }; void main() { bool start = true; int i = 0; while(start){ auto obj = new MyClass(); obj.show(); Thread.sleep(5.msecs); //obj.destroy; //GC.free(cast(void *)obj); ++i; if (i > 2) break; } } the code will be : 341 core.exception.InvalidMemoryOperationError@src/core/exception.d(679): Invalid memory operation core.exception.InvalidMemoryOperationError@src/core/exception.d(679): Invalid memory operation .why is it? if < obj.destroy; > is exec. the code will not errno. I am in 2.069, on opensuse leap 42.1 X86_64 dmd -v DMD64 D Compiler v2.069 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
Re: Why is it a memory ERRO.
Ok.Thank you. and i want to know how to know when the GC start runing?
How can i track the GC when it's runing?
I want to know How can i track the GC when it's runing? And Which algorithm is D's GC used,only Scan-Mark?