Re: discrimination of constructors with same number of parameters

2010-12-30 Thread sybrandy
On 12/30/2010 08:46 AM, Lutger Blijdestijn wrote: sybrandy wrote: Why not have something like this: this (int[] data, string text, bool isMessage = false) {...} Then, if you just pass in two parameters you treat it as a filename and if you pass in a "true" for the third paramet

Re: discrimination of constructors with same number of parameters

2010-12-30 Thread sybrandy
Why not have something like this: this (int[] data, string text, bool isMessage = false) {...} Then, if you just pass in two parameters you treat it as a filename and if you pass in a "true" for the third parameter, it's a message. It's not quite what you're looking for, but it's simple and p

Re: Creating an array of unique elements

2010-12-27 Thread sybrandy
I've done something like this before using associative arrays. I would rely on the fact that the keys have to be unique to produce my unique array. So, in this case, any value you want to store you would save like this: array[value] = 1; Regardless of whether or not the value already exists

Re: Memory allocation faile on string concat

2010-11-10 Thread sybrandy
On 11/10/2010 11:33 AM, Xie wrote: Can't run a simple program. What's wrong, GC? import std.stdio; import std.date; void f0() { wstring a[]; foreach(i; 0 .. 100_000_000) { a ~= " "w; } } void main() { auto r = benchmark!(f0)(1);

Exception with MmFile

2010-10-30 Thread sybrandy
Hello, I'm currently getting a message stating that an exception has been thrown when finalizing an instance of std.mmfile.MmFile. What would cause this? I've used MmFile in other cases without any problems. However, in this case I'm using it as a member within a class. I see nothing in th

RosettaCode: Echo Server

2010-09-03 Thread sybrandy
Hello, I decided to exercise my skills in D a bit and wrote an implementation for an echo server using D. I figure before I post it to the site, I'd post it here for comments as I'd like to get the best possible version on the site vs. something that's half-assed. Considering I'm very new t

Re: typedef alternative

2010-08-14 Thread sybrandy
I can't recall if you can do this with structs, but if you use classes, you should be able to define a "Date Part" class that has all of the methods and data you want. Then, you just derive three sub-classes. For example (and I hope the syntax is right): class DatePart { this(int f) {

Re: Grokking concurrency, message passing and Co

2010-07-12 Thread sybrandy
I'd expect databases to have quite odd performance characteristics compared to a more normal application though; You'd expect them to be IO bound most of the time, so having more threads than cores sounds like a reasonable thing to do. If you aren't waiting on the disc, then more threads aren't g

Re: Grokking concurrency, message passing and Co

2010-07-11 Thread sybrandy
The rule of thumb is don't bother spawning more threads than you have cpus. You're just wasting resources mostly. You REALLY don't want more threads trying to run than you have cores. Threads in a wait state, are less of an issue, but they still use up resources. Personally I'd never use mor

Re: Issue with Curry

2010-06-24 Thread sybrandy
On 06/24/2010 06:54 PM, sybrandy wrote: Hello, I tried using the curry function last night and I ran into a compilation issue. Here's a simple example that demonstrates the issue: import std.functional; import std.stdio; void strwrite(string input) { writeln(input); } alias curry!(str

Issue with Curry

2010-06-24 Thread sybrandy
Hello, I tried using the curry function last night and I ran into a compilation issue. Here's a simple example that demonstrates the issue: import std.functional; import std.stdio; void strwrite(string input) { writeln(input); } alias curry!(strwrite, "foo") writefoo; void main() {

Appending to Shared Arrays

2010-03-03 Thread sybrandy
Hello, I have a shared array that I'm trying to append data to, but the compiler keeps telling me that I can't convert to a shared(Fiber) from a regular or const Fiber. What is the correct way to do this? Casey

Re: raii

2010-02-28 Thread sybrandy
I have two questions for you: 1) Are class destructors not good enough? If so, why? 2) Have you looked into static destructors? I created a logging library and that worked perfect for me to ensure that if I killed the program via Ctrl-C, it would flush the output buffer and close the file

Re: Simple Socket Server Code

2010-02-24 Thread sybrandy
On 02/24/2010 09:00 AM, daoryn wrote: Check the "samples" dir inside the dmd instalation folder. Theres a sample there named "listener.d" that shows how to use D sockets. If you're using DMD2, the listener.d file is broken. You'll have to convert it into D2 yourself. I actually did look at tha

Simple Socket Server Code

2010-02-23 Thread sybrandy
All, Does anyone know where I can get a simple example of writing a server in D? Just a stupid little echo server would be fine. I'm trying to write one myself, but for some reason it doesn't seem to be accepting any connections. I figure it's something stupidly simple, but I'm just not se

Re: Creating a logging library and have questions

2010-02-06 Thread sybrandy
I second Rainer. A logging system should commit (at least) error messages immediately, particularly if the application has multiple threads. Otherwise it is going to make debugging a crashing system a nightmare. When I do it I just stick 'synchronized' in front of the statement that does the

Re: Creating a logging library and have questions

2010-02-03 Thread sybrandy
On 02/03/2010 12:03 AM, Rainer Deyke wrote: sybrandy wrote: 1) I use the current core.thread library and put all my messages in a buffer that the thread checks periodically, pulls off a new message, and then writes it to a file. There will be some work to make sure nothing collides with each

Creating a logging library and have questions

2010-02-02 Thread sybrandy
Hello, Since I'm continuing to write software in D (no, nothing special...just pet projects) I felt that I needed to create a library to handle logging to a file. I have a good start and it seems to work pretty well. I even have a couple ideas left to implement to make it better, however I'

Re: D memory consumption/runtime speed problem

2010-01-14 Thread sybrandy
Using a small buffer as suggested by Daniel Keep and Steven Schveighoffer significantly improved performance. Now down to about 5 seconds. I ended up using the static array buffer since the encodeNumber function will be in its own file in my resulting program, so I can keep it private. Do

D memory consumption/runtime speed problem

2010-01-13 Thread sybrandy
Hello, I've been writing a bit of compression code and I noticed some strange behavior that's driving me a bit batty. I don't know if it's a bug with D or something I did. All I know is I can't figure it out. Below is the simplified version of the code as a single file. It takes two param

Re: D2 Singleton / Thread Local Storage issue

2009-08-30 Thread sybrandy
Thanks for the info. I was hoping that there would be a different solution, but I guess I should have expected that I may have to wait for the feature to stabilize. Casey

D2 Singleton / Thread Local Storage issue

2009-08-29 Thread sybrandy
Hello, I've been learning D for some time now and I recently was trying to do some work with threads, but I'm having a problem getting it to work. I'm trying to create a singleton that can be accessed between threads, however I get an access violation when I try to run the following code. If