Re: Is GC.setAttr(p, GC.BlkAttr.NO_MOVE) guaranteed to work?

2014-07-01 Thread Rainer Schuetze via Digitalmars-d-learn
On 02.07.2014 08:17, Ali Çehreli wrote: There is an example in GC.addRoot() documentation where the programmer is trying to mark a memory block as NO_MOVE: http://dlang.org/phobos/core_memory.html#.GC.addRoot auto context = new Object; GC.addRoot(cast(void*)context); GC.setA

Is GC.setAttr(p, GC.BlkAttr.NO_MOVE) guaranteed to work?

2014-07-01 Thread Ali Çehreli via Digitalmars-d-learn
There is an example in GC.addRoot() documentation where the programmer is trying to mark a memory block as NO_MOVE: http://dlang.org/phobos/core_memory.html#.GC.addRoot auto context = new Object; GC.addRoot(cast(void*)context); GC.setAttr(cast(void*)context, GC.BlkAttr.NO_MOVE);

Re: struct, ref in, and UFCS

2014-07-01 Thread Puming via Digitalmars-d-learn
On Tuesday, 1 July 2014 at 13:53:12 UTC, Ali Çehreli wrote: On 07/01/2014 03:21 AM, Puming wrote: > I can safely assume ref is better than pointer here I agree. > because it plays nicely with UFCS. I don't understand that part. :) The following is the same program with just two differences:

Re: why does clearing an array set its capacity to 0?

2014-07-01 Thread bearophile via Digitalmars-d-learn
Vlad Levenfeld: Will there be a @nogc or @noheap flag in 2.066? A @nogc. (The idea of @noheap was refused and I've closed down the Enhancement request). Bye, bearophile

Re: why does clearing an array set its capacity to 0?

2014-07-01 Thread Vlad Levenfeld via Digitalmars-d-learn
How did you allocate your array? The GC has the APPENDABLE attribute special for memory blocks that are going to be used as slices: I allocated with new T[n]. I've tried allocating with both the APPENDABLE and NO_SCAN blocks but beyond a certain allocation size this doesn't work, I get a repo

Re: why does clearing an array set its capacity to 0?

2014-07-01 Thread Ali Çehreli via Digitalmars-d-learn
On 07/01/2014 03:51 PM, Vlad Levenfeld wrote: > Thanks for your replies. The article was quite helpful in clarifying > some questions I had. > > I decided to benchmark the different append methods (with > ["releaseMode", "inline", "noBoundsCheck", "optimize"]) by appending > 10,000 elements to ar

Re: why does clearing an array set its capacity to 0?

2014-07-01 Thread Vlad Levenfeld via Digitalmars-d-learn
Thanks for your replies. The article was quite helpful in clarifying some questions I had. I decided to benchmark the different append methods (with ["releaseMode", "inline", "noBoundsCheck", "optimize"]) by appending 10,000 elements to arrays with ~=, Appender, with and without first r

Re: Bidirectional PIPE, and do not wait for child to terminate

2014-07-01 Thread Justin Whear via Digitalmars-d-learn
On Tue, 01 Jul 2014 21:00:58 +, Justin Whear wrote: > On Tue, 01 Jul 2014 20:42:14 +, seany wrote: > >> On Tuesday, 1 July 2014 at 15:32:31 UTC, Justin Whear wrote: >> >> >>> A pipe can be unidirectional only, but you can use more than one. >> >> and what about FIFO or LIFO s? > > You

Re: Bidirectional PIPE, and do not wait for child to terminate

2014-07-01 Thread Justin Whear via Digitalmars-d-learn
On Tue, 01 Jul 2014 20:42:14 +, seany wrote: > On Tuesday, 1 July 2014 at 15:32:31 UTC, Justin Whear wrote: > > >> A pipe can be unidirectional only, but you can use more than one. > > and what about FIFO or LIFO s? You can use the C mkfifo function (import core.sys.posix.sys.stat) to cre

Re: Bidirectional PIPE, and do not wait for child to terminate

2014-07-01 Thread seany via Digitalmars-d-learn
On Tuesday, 1 July 2014 at 15:32:31 UTC, Justin Whear wrote: A pipe can be unidirectional only, but you can use more than one. and what about FIFO or LIFO s?

Re: why does clearing an array set its capacity to 0?

2014-07-01 Thread Ivan Kazmenko via Digitalmars-d-learn
On Tuesday, 1 July 2014 at 13:03:54 UTC, Vlad Levenfeld wrote: I was mistaken earlier, decrementing the length counter also sets the capacity to 0. Besides just learning to use assumeSafeAppend (as mentioned already), I'd also recommend reading the article on D slices to deeper understand the

Re: Bidirectional PIPE, and do not wait for child to terminate

2014-07-01 Thread Justin Whear via Digitalmars-d-learn
On Tue, 01 Jul 2014 13:00:47 +, seany wrote: > 1. Bidirectional Pipes - I would like to write something to a second > program (UNIX, resp GNU/LINUX environment) and listen to what it has to > say. BTW, for convenience, you probably want to use pipeProcess or pipeShell.

Re: zipWith or map

2014-07-01 Thread Gecko via Digitalmars-d-learn
On Tuesday, 1 July 2014 at 18:13:42 UTC, bearophile wrote: Gecko: is there a scanl like in haskell (like reduce but returning the intermediate results as well). Request in bugzilla, ma no Phobos pull request implementation yet. Bye, bearophile Here's the issue https://issues.dlang.org/sh

Re: zipWith or map

2014-07-01 Thread bearophile via Digitalmars-d-learn
Gecko: is there a scanl like in haskell (like reduce but returning the intermediate results as well). Request in bugzilla, ma no Phobos pull request implementation yet. Bye, bearophile

Re: zipWith or map

2014-07-01 Thread Gecko via Digitalmars-d-learn
On Tuesday, 1 July 2014 at 17:51:17 UTC, Justin Whear wrote: There is a zip function in std.range. It produces a range of tuples that you can then map over. Thank you, I couldnt figure out what std.range.zip makes from the documentation. something else : is there a scanl like in haskell (

Re: zipWith or map

2014-07-01 Thread Justin Whear via Digitalmars-d-learn
On Tue, 01 Jul 2014 17:49:53 +, Gecko wrote: > Hello, > is there a fancy way do a zipWith (map with multiple ranges). There is > no in std.algorithm, or does it have a different name? There is a zip function in std.range. It produces a range of tuples that you can then map over.

zipWith or map

2014-07-01 Thread Gecko via Digitalmars-d-learn
Hello, is there a fancy way do a zipWith (map with multiple ranges). There is no in std.algorithm, or does it have a different name?

Re: why does clearing an array set its capacity to 0?

2014-07-01 Thread Chris Cain via Digitalmars-d-learn
In short: Why is this, and what do I do about it? http://dlang.org/phobos/object.html#.assumeSafeAppend On Tuesday, 1 July 2014 at 12:33:15 UTC, Vlad Levenfeld wrote: I'm trying to implement some wrappers atop preallocated arrays, so I'm calling reserve in the constructor, have an invariant t

Re: Bidirectional PIPE, and do not wait for child to terminate

2014-07-01 Thread Justin Whear via Digitalmars-d-learn
On Tue, 01 Jul 2014 13:00:47 +, seany wrote: > I read the manual here: > http://dlang.org/phobos/std_process.html#.spawnProcess > > However, I need to (I can not remember, nor can I find in the forums any > info thereon) create > > 1. Bidirectional Pipes - I would like to write something to

Re: Thread-safety and lazy-initialization of libraries

2014-07-01 Thread Sean Kelly via Digitalmars-d-learn
On Monday, 30 June 2014 at 20:53:25 UTC, Sergey Protko wrote: Is there any proper way to do on-demand lazy-initialization of used library, which will be also thread-safe? How do i need to handle cases where some methods, which requires library to be initialized, called from different threads

Re: struct, ref in, and UFCS

2014-07-01 Thread Ali Çehreli via Digitalmars-d-learn
On 07/01/2014 03:21 AM, Puming wrote: > I can safely assume ref is better than pointer here I agree. > because it plays nicely with UFCS. I don't understand that part. :) The following is the same program with just two differences: prompt() takes a pointer and 'server' is a pointer. import

Bidirectional PIPE, and do not wait for child to terminate

2014-07-01 Thread seany via Digitalmars-d-learn
I read the manual here: http://dlang.org/phobos/std_process.html#.spawnProcess However, I need to (I can not remember, nor can I find in the forums any info thereon) create 1. Bidirectional Pipes - I would like to write something to a second program (UNIX, resp GNU/LINUX environment) and lis

Re: why does clearing an array set its capacity to 0?

2014-07-01 Thread Vlad Levenfeld via Digitalmars-d-learn
I was mistaken earlier, decrementing the length counter also sets the capacity to 0.

why does clearing an array set its capacity to 0?

2014-07-01 Thread Vlad Levenfeld via Digitalmars-d-learn
I'm trying to implement some wrappers atop preallocated arrays, so I'm calling reserve in the constructor, have an invariant to ensure that the array.ptr never moves, and use in-contracts to make sure any insertion and appends don't put me over the array capacity. I find that I'm able to safe

Re: How to test templates for equality?

2014-07-01 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 1 July 2014 at 05:58:19 UTC, Uranuz wrote: Thanks for quick response. I really forget to look into language __traits statement. Another option: enum isFoo(T) = is(T == Foo!P, P...); By using such an is-expression you get the parameters Foo was instantiated with as an added bonus.

Re: struct, ref in, and UFCS

2014-07-01 Thread Puming via Digitalmars-d-learn
On Tuesday, 1 July 2014 at 07:53:27 UTC, bearophile wrote: Puming: is this a good practice to use `ref in` with structs instead of traditional pointer syntax (which does not play well with UFCS though) ? Is there any perfomance implications with `ref in`? I tried that it does not seem to copy

Re: struct, ref in, and UFCS

2014-07-01 Thread bearophile via Digitalmars-d-learn
Puming: is this a good practice to use `ref in` with structs instead of traditional pointer syntax (which does not play well with UFCS though) ? Is there any perfomance implications with `ref in`? I tried that it does not seem to copy the parameter value, A "ref" is equivalent to a pointer t