How to implement immutable ring buffer?

2015-05-27 Thread drug via Digitalmars-d-learn
Could somebody share his thoughts on the subject? Would it be efficient? Is it possible to avoid memory copying to provide immutability? To avoid cache missing ring buffer should be like array, not list, so it's possible that the whole buffer should be moved. Is it neccessary to be real

Re: problem with gc?

2015-05-27 Thread Anonymouse via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 08:42:01 UTC, zhmt wrote: When I enable the --profle, get something like this, it doesnt give me too much help: [...] Tried callgrind and kcachegrind? If nothing else it's better at illustrating the same output, assuming you have graphviz/dot installed. Given

Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 09:39:42 UTC, Anonymouse wrote: On Wednesday, 27 May 2015 at 08:42:01 UTC, zhmt wrote: When I enable the --profle, get something like this, it doesnt give me too much help: [...] Tried callgrind and kcachegrind? If nothing else it's better at illustrating the

Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn
When I enable the --profle, get something like this, it doesnt give me too much help: Timer Is 3579545 Ticks/Sec, Times are in Microsecs Num TreeFuncPer CallsTimeTimeCall 1298756 4996649885 49875773773840

Re: How to implement immutable ring buffer?

2015-05-27 Thread drug via Digitalmars-d-learn
On 27.05.2015 11:04, thedeemon wrote: This whole idea sounds self-contradictory. Ring buffer is a mutable-array-based implementation of something, for example of a queue. You can ask about immutable implementations of a queue, but that would be another question, not involving a ring buffer.

Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn
@jklp And also you could try to surround the whole block with `GC.disable` and `GC.enable`. This would help to determine if the GC is involved: --- Ptr!Conn conn = connect(127.0.0.1,8881); GC.disable; ubyte[100] buf; string str; for(int i=0; iN; i++) { str = format(%s,i);

Re: How to implement immutable ring buffer?

2015-05-27 Thread Daniel Kozák via Digitalmars-d-learn
On Wed, 27 May 2015 09:20:52 + drug via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Could somebody share his thoughts on the subject? Would it be efficient? Is it possible to avoid memory copying to provide immutability? To avoid cache missing ring buffer should be like

Re: problem with gc?

2015-05-27 Thread Anonymouse via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 10:24:59 UTC, zhmt wrote: @Anonymouse Thank u very much, I have tried this: valgrind --tool=callgrind ./gamelibdtest callgrind_annotate callgrind.out.29234 Ir

Re: How to implement immutable ring buffer?

2015-05-27 Thread thedeemon via Digitalmars-d-learn
This whole idea sounds self-contradictory. Ring buffer is a mutable-array-based implementation of something, for example of a queue. You can ask about immutable implementations of a queue, but that would be another question, not involving a ring buffer. What do you want to do with this

Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn
What happened when the code changes a little? Who will give an explaination,Thanks a lot? what happend if you use sformat instead? Ptr!Conn conn = connect(127.0.0.1,8881); ubyte[100] buf; char[100] buf2; for(int i=0; iN; i++) { auto str = sformat(buf2, %s,i);

Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn
If I pass a timeout with 1ms to epoll_wait,the cpu will not be busy when throughput falls down.

Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn
It seems that dlang library is not so effient?

Re: How to implement immutable ring buffer?

2015-05-27 Thread drug via Digitalmars-d-learn
On 27.05.2015 11:10, Daniel Kozák via Digitalmars-d-learn wrote: On Wed, 27 May 2015 09:20:52 + drug via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Could somebody share his thoughts on the subject? Would it be efficient? Is it possible to avoid memory copying to provide

Re: problem with gc?

2015-05-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/27/15 2:42 AM, zhmt wrote: When I enable the --profle, get something like this, it doesnt give me too much help: I don't see any GC function here, I don't think you are are focusing on the right portion of the code. Seems like the gamelib library is consuming all the time. You may want

Null argument and function resolution

2015-05-27 Thread Andrea Fontana via Digitalmars-d-learn
Check this example: http://dpaste.dzfl.pl/53f85bae4382 Calling with null, both c-tor match. Is there a way to solve this? Something like: this(in ubyte* data) if( ??? ) { } Andrea

Re: problem with gc?

2015-05-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 10:27:08 UTC, zhmt wrote: It seems that dlang library is not so effient? The gamelibd could be doing a lot more than just echoing... it sounds to me that your socket might be blocking and epoll is busy looping waiting for it to become available again.

Re: Prevent slices from referencing old array after realocation?

2015-05-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/27/15 1:55 AM, Gr8Ape wrote: I'm writing a program that handles lots of slices of larger arrays. I need the data of each of them all together for one operation, but otherwise it's more convenient to handle the elements in small groups. I could just store a pointer to my array, an offset,

problem with custom predicate

2015-05-27 Thread via Digitalmars-d-learn
I am trying to use a Container class with a custom predicate, but the following code does not compile. Any hints on how to do it? import std.container; class C { int[] prio; RedBlackTree!(int, (a,b)=prio[a]prio[b]) tree; } I think I understand the reason why this does not work (the

Re: Null argument and function resolution

2015-05-27 Thread Adam D. Ruppe via Digitalmars-d-learn
Two options: 1) add an overload that takes typeof(null) this(typeof(null)) { /* handles the null literal specially */ } 2) Cast null to a specific type when making it: new YourClass(cast(ubyte*) null);

Re: problem with custom predicate

2015-05-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/27/15 9:59 AM, Meta wrote: I thought unaryFun *does* work with all callables, including structs/classes with opCall? It (binaryFun actually) declares an alias. But you need an actual instance to use in this case. You simply can't declare that in a type definition, and it won't be set

Re: problem with gc?

2015-05-27 Thread via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 05:48:13 UTC, zhmt wrote: The code you posted is the client code, but the issue seems to be on the server side. Can you post the server code and also the timing code?

Re: Prevent slices from referencing old array after realocation?

2015-05-27 Thread via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 07:55:29 UTC, Gr8Ape wrote: You can keep an index and a count instead of a slice. If you know your data well, you can exploit this knowledge, and this has the potential to save you many bytes per slice when dealing with large data sets. Depending on your access

Re: problem with custom predicate

2015-05-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/27/15 9:11 AM, Simon =?UTF-8?B?QsO8cmdlciI=?= simon.buer...@rwth-aachen.de wrote: On Wednesday, 27 May 2015 at 14:58:39 UTC, drug wrote: Do you want to dynamically change priority? Actually yes. In my actual code I am not using a RedBlackTree but my own Container (a heap with the

Re: problem with custom predicate

2015-05-27 Thread Timon Gehr via Digitalmars-d-learn
On 05/27/2015 05:30 PM, Steven Schveighoffer wrote: On 5/27/15 9:11 AM, Simon =?UTF-8?B?QsO8cmdlciI=?= simon.buer...@rwth-aachen.de wrote: On Wednesday, 27 May 2015 at 14:58:39 UTC, drug wrote: Do you want to dynamically change priority? Actually yes. In my actual code I am not using a

Re: problem with custom predicate

2015-05-27 Thread Meta via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 15:30:28 UTC, Steven Schveighoffer wrote: On 5/27/15 9:11 AM, Simon =?UTF-8?B?QsO8cmdlciI=?= simon.buer...@rwth-aachen.de wrote: On Wednesday, 27 May 2015 at 14:58:39 UTC, drug wrote: Do you want to dynamically change priority? Actually yes. In my actual code I am

Re: Null argument and function resolution

2015-05-27 Thread Andrea Fontana via Digitalmars-d-learn
The first answer is the one I was looking for. Very useful. You should add to next this week in d tips. On Wednesday, 27 May 2015 at 14:09:48 UTC, Adam D. Ruppe wrote: Two options: 1) add an overload that takes typeof(null) this(typeof(null)) { /* handles the null literal specially */ } 2)

Re: problem with custom predicate

2015-05-27 Thread drug via Digitalmars-d-learn
On 27.05.2015 13:50, Simon Bürger simon.buer...@rwth-aachen.de wrote: I am trying to use a Container class with a custom predicate, but the following code does not compile. Any hints on how to do it? import std.container; class C { int[] prio; RedBlackTree!(int, (a,b)=prio[a]prio[b])

Re: problem with custom predicate

2015-05-27 Thread via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 14:58:39 UTC, drug wrote: Do you want to dynamically change priority? Actually yes. In my actual code I am not using a RedBlackTree but my own Container (a heap with the possibility to modify elements inside), which is notified when prio changes so it can do a

Re: Null argument and function resolution

2015-05-27 Thread ketmar via Digitalmars-d-learn
On Wed, 27 May 2015 14:09:47 +, Adam D. Ruppe wrote: Two options: 1) add an overload that takes typeof(null) this(typeof(null)) { /* handles the null literal specially */ } you keep breaking my box of thinking. ;-) never thought about such declaration. signature.asc Description: PGP

Re: problem with custom predicate

2015-05-27 Thread Meta via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 17:56:27 UTC, Steven Schveighoffer wrote: On 5/27/15 9:59 AM, Meta wrote: I thought unaryFun *does* work with all callables, including structs/classes with opCall? It (binaryFun actually) declares an alias. But you need an actual instance to use in this case.

Re: Null argument and function resolution

2015-05-27 Thread Meta via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 19:38:16 UTC, ketmar wrote: On Wed, 27 May 2015 14:09:47 +, Adam D. Ruppe wrote: Two options: 1) add an overload that takes typeof(null) this(typeof(null)) { /* handles the null literal specially */ } you keep breaking my box of thinking. ;-) never thought

Re: Null argument and function resolution

2015-05-27 Thread Timon Gehr via Digitalmars-d-learn
On 05/27/2015 10:09 PM, Meta wrote: On Wednesday, 27 May 2015 at 19:38:16 UTC, ketmar wrote: On Wed, 27 May 2015 14:09:47 +, Adam D. Ruppe wrote: Two options: 1) add an overload that takes typeof(null) this(typeof(null)) { /* handles the null literal specially */ } you keep breaking

Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 05:51:21 UTC, zhmt wrote: I noticed that the cpu% falls from 99% down to 4% as well when the throughput falls down. I tried again for several times, the cpu is still busy, 98.9%.

Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn
I think it is not problem of gc, it is my fault: The operations is serialized: clent send - server recv - server send - client recv, so if one operation takes too long time, the throughput will definitely fall down. I cant explain why it so fast when buffer is big enough, and so low when

Re: problem with gc?

2015-05-27 Thread zhmt via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 19:04:53 UTC, Márcio Martins wrote: On Wednesday, 27 May 2015 at 05:48:13 UTC, zhmt wrote: The code you posted is the client code, but the issue seems to be on the server side. Can you post the server code and also the timing code? @Márcio Martins here is

Template problem - if arg[0]==something; call arg[1];

2015-05-27 Thread wobbles via Digitalmars-d-learn
I have some code that I'd really like to template-ize. Currently, I've the same construct all over my code, repeated(yet slightly different) about 15 times. Too much for me, and I'd like to make it into a template. This is a sample of my current code: http://dpaste.dzfl.pl/76814846898e I

Re: Template problem - if arg[0]==something; call arg[1];

2015-05-27 Thread ketmar via Digitalmars-d-learn
On Wed, 27 May 2015 22:49:18 +, ketmar wrote: i.e. `constructCases~(Aliases[2..$])` `constructCases!(Aliases[2..$])`, of course ;-) signature.asc Description: PGP signature

Re: Template problem - if arg[0]==something; call arg[1];

2015-05-27 Thread ketmar via Digitalmars-d-learn
On Wed, 27 May 2015 22:35:54 +, wobbles wrote: quick looking thru your code raises two questions: 1. didn't you forgot to add `.stringof` in `constructCases`? 2. didn't you forgot `!` in `constructCases(Aliases[2..$])`? i.e. `constructCases~(Aliases[2..$])` it may work with that.

Re: problem with gc?

2015-05-27 Thread thedeemon via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 05:48:13 UTC, zhmt wrote: What happened when the code changes a little? Who will give an explaination,Thanks a lot? Yes, on the first sight it looks like your allocations in the loop make GC spend too much time. I don't think scope does anything here. Try adding

Re: problem with gc?

2015-05-27 Thread jklp via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 05:48:13 UTC, zhmt wrote: I am writing a echoclient, as below: Ptr!Conn conn = connect(127.0.0.1,8881); ubyte[100] buf; for(int i=0; iN; i++) { scope string str = format(%s,i); conn.write((cast(ubyte*)str.ptr)[0..str.length]);

Re: problem with gc?

2015-05-27 Thread Daniel Kozák via Digitalmars-d-learn
On Wed, 27 May 2015 05:48:11 + zhmt via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I am writing a echoclient, as below: Ptr!Conn conn = connect(127.0.0.1,8881); ubyte[100] buf; for(int i=0; iN; i++) { scope string str = format(%s,i);

Prevent slices from referencing old array after realocation?

2015-05-27 Thread Gr8Ape via Digitalmars-d-learn
I'm writing a program that handles lots of slices of larger arrays. I need the data of each of them all together for one operation, but otherwise it's more convenient to handle the elements in small groups. I could just store a pointer to my array, an offset, and a length but since I'm using D

Re: problem with gc?

2015-05-27 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 27 May 2015 at 05:48:13 UTC, zhmt wrote: I am writing a echoclient, as below: Ptr!Conn conn = connect(127.0.0.1,8881); ubyte[100] buf; for(int i=0; iN; i++) { scope string str = format(%s,i); conn.write((cast(ubyte*)str.ptr)[0..str.length]);