Re: is there a cleaner way to new a static sized array?

2010-02-25 Thread grauzone
BCS wrote: I need a function that works like the following: T* New(T)() { return new T; } But that also works with static arrays: auto i = New!(int)(); auto a = New!(int[27])(); The cleanest solution I can think of is: T* New(T)() { return (new T[1]).ptr; } but that seems ugly. Any id

Re: exceptions

2010-02-25 Thread grauzone
Ellery Newcomer wrote: On 02/24/2010 12:37 PM, Robert Clipsham wrote: On 24/02/10 17:51, Ellery Newcomer wrote: import tango.core.tools.TraceExceptions; If you want to use gdb then type 'b _d_throw_exception' (or 'b _d_throw' for dmd) before you run your app. This will break on eve

Re: immutable string literal?

2010-02-22 Thread grauzone
Steven Schveighoffer wrote: On Mon, 22 Feb 2010 09:27:57 -0500, strtr wrote: Thanks, I understand. But, how about a runtime error? Isn't a literal placed in easy to identify should-only-read memory? A segfault is a runtime error. The problem with Windows is it doesn't throw an error on writ

Re: Why isn't == used to compare structs

2010-02-09 Thread grauzone
Don wrote: Trass3r wrote: Why isn't == used to compare the struct members in the code above? I mean, if I compare the structs with == it could also use == to compare the members. If I use "is" to compare the structs it could use "is" to compare them members. Structs are compared *bitwise*!

Re: converting a byte array to a struct array?

2010-01-02 Thread grauzone
Trass3r wrote: grauzone schrieb: Second, the bug: casting arrays at compiletime seems to behave differently from casting at runtime. Casting at compiletime doesn't reinterpret cast, it does conversion! Demonstration here: http://codepad.org/OGjXADdu Feel free to file some bug re

Re: What wrong did i do? (key in hashtable is always null)

2009-12-31 Thread grauzone
The Anh Tran wrote: This is just a small D exercise. I port c++ knucleotide from shootout.alioth.debian.org Issue 1: If i manually listing hashtable contents, the key does exist in that ht. But (key in hash_table) always yield null. Worse, if i use: "auto val = ht[key]", an exception is thrown

Re: Memory RAM usage

2009-12-31 Thread grauzone
bearophile wrote: (I have recently seen a 13X speedup in a not synthetic program just modifying how memory is used and reducing memory usage, keeping the same algorithm. I can show you an URL if you want). Yes, please do! Do you know how can Free Pascal use so little RAM? Here in this nbody b

Re: define new types within templates

2009-12-30 Thread grauzone
teo wrote: There was a way to define new types within templates and I think that I have seen that demonstrated here in the newsgroups, but cannot find it now. Can someone help me please? I would like to do something like this: template MyTemplate(T) { struct T ~ "Struct" // define FooStruc

Re: converting a byte array to a struct array?

2009-12-30 Thread grauzone
Trass3r wrote: I got some RGB palette in a byte array which I'd like to convert or "map" to an RGB struct array, isn't this easily possible without using dozens of struct constructors? RGB[256] PALETTE = cast(RGB[256]) [ 0x00, 0x00, 0x00, 0xE3, 0x53, 0x00, 0xCF, 0x4B, 0x07, 0xBF, 0x43

Re: floating point verification using is?

2009-12-18 Thread grauzone
bearophile wrote: Steven Schveighoffer: If I have 2 identical floating point values, how do I ensure they are binary equivalents of eachother? Try this inside std.math of Phobos2: bool isIdentical(real x, real y); I thought 'a is b' would work, but it just morphs into a == b, which isn't

Re: Immutable & circular imports

2009-12-16 Thread grauzone
Tomek Sowiński wrote: Amusing things happen when immutable arguments and circular imports are put together: -- module hello; import test; struct Strukt { Staly* s; } -- module test; import hello; immut

Re: Tempated class instantiation

2009-12-16 Thread grauzone
Mike L. wrote: I'm making a class template that only works with strings, so I thought it'd be good to instantiate each template with char, wchar, and dchar right in the template's module so that when it's compiled it'll be part of the .obj file and won't have to compile it for every other proj

Re: Compilation constants

2009-11-11 Thread grauzone
Phil Deets wrote: On Wed, 11 Nov 2009 13:34:32 -0500, Phil Deets wrote: On Wed, 11 Nov 2009 13:30:17 -0500, Phil Deets wrote: On Wed, 11 Nov 2009 08:50:48 -0500, bearophile wrote: In a C program I have a numeric constant SIZE (that is in [1,32]), that I can define when I compile the co

Re: FMOD working with Windows

2009-11-10 Thread grauzone
Joel Christensen wrote: grauzone wrote: Joel Christensen wrote: FMOD sound (record and play) is off D Programming web site. http://wiki.dprogramming.com/FMod/HomePage I followed instructions from the web site. But one instruction said to use 'coffimplib.exe' but I couldn't

Re: FMOD working with Windows

2009-11-09 Thread grauzone
Joel Christensen wrote: FMOD sound (record and play) is off D Programming web site. http://wiki.dprogramming.com/FMod/HomePage I followed instructions from the web site. But one instruction said to use 'coffimplib.exe' but I couldn't see where it is to download it, and one link wasn't found (

Re: How to run unittests?

2009-10-31 Thread grauzone
al wrote: It seems that unittests are not run (I've tried putting while(1){} and writef() there - no effect). Even this code doesn't run assert(): import std.stdio; int main(string[] args) { assert(args.length == -1); writef("shouldn't work!"); return 0; } I'm using:

Re: How to override function?

2009-10-22 Thread grauzone
Zarathustra wrote: I would like to know, how to override function if subclass and super class are located in the same package and different modules. For instance when they are in the same module: //___ module main; class Foo{ this(){ proc(); } void

Re: Sorry, I just love templates, AAs and mixins :)

2009-10-17 Thread grauzone
Saaa wrote: public void addToAA(char[] var_name, KT, ET)(KT key, ET element) { mixin(ET.stringof~`[]* elements = key in `~var_name~`;`); if( elements == null ) { ET[] temp; temp.length = 1; temp[0] = element; mixin(var_name~`[key] = temp;`); } else { (*elements).le

Re: Sizeof class instance

2009-10-04 Thread grauzone
Justin Johansson wrote: grauzone Wrote: Justin Johansson wrote: How does one determine the sizeof (in bytes) of an instance of a class in D? .sizeof works as advertised for structs, but for reference types, .sizeof yields the sizeof the referencing variable (effectively same as size of a

Re: Sizeof class instance

2009-10-04 Thread grauzone
Justin Johansson wrote: How does one determine the sizeof (in bytes) of an instance of a class in D? .sizeof works as advertised for structs, but for reference types, .sizeof yields the sizeof the referencing variable (effectively same as size of a pointer) and not the size of the underlying in

Re: Linking in an .so on linux with rebuild?

2009-09-22 Thread grauzone
Daniel Keep wrote: I found a solution. See http://stackoverflow.com/questions/335928/linux-gcc-linking-ld-cannot-find-a-library-that-exists For me, I needed readline and history, so I did this: $ cd /lib $ sudo ln -s libreadline.so.5 libreadline.so $ sudo ln -s libhistory.so.5 libhistory.so A

Re: Linking in an .so on linux with rebuild?

2009-09-22 Thread grauzone
Nick Sabalausky wrote: I can't seem to get that to work. Tried all sorts of stuff. Off the top of my head: -ll This should work. If the lib is named "libsomething", don't include the "lib": -llsomething Excluding the "lib" seems to be standard on Unix-like OSes. -ll.so "-L-l " "-L-l .so"

Re: D1: std.md5: corrections for the given example

2009-09-19 Thread grauzone
notna wrote: grauzone schrieb: md5_example_2.d(7): expression expected, not 'auto' md5_example_2.d(7): found 'len' when expecting ')' md5_example_2.d(7): found '=' instead of statement (this is line 7 after I removed comments and blank lines from

Re: D1: std.md5: corrections for the given example

2009-09-18 Thread grauzone
downs wrote: Stewart Gordon wrote: downs wrote: while (auto len = file.readBlock(buffer.ptr, buffer.sizeof)) md5_example_2.d(7): expression expected, not 'auto' md5_example_2.d(7): found 'len' when expecting ')' md5_example_2.d(7): found '=' instead of statement (this is line 7 after I rem

Re: How does D cope with aliasing

2009-09-09 Thread grauzone
#ponce wrote: Stewart Gordon Wrote: My recollection of reading the spec is that a D compiler is allowed to optimise by assuming no pointer aliasing. But I can't remember at the moment where I read this. I don't know if this is neat or nasty for a compiler to do so. OT : Is there a DMD swi

Re: Any way to workaround Optlink crash?

2009-09-02 Thread grauzone
div0 wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jérôme M. Berger wrote: Max Samukha wrote: Tom S wrote: Max Samukha wrote: COFF/ELF output would not be that bad though, at least if there's some linker that supports these *and* its license allows it to be bundled with DMD. I doubt s

Re: Error: constant false is not an lvalue

2009-08-30 Thread grauzone
I wouldn't be surprised if W himself has forgotten about this rule, since other parts of the spec make no mention of it, or seem to depend on the default-initialization of variables. "If the Initializer is void, however, the variable is not initialized. If its value is used before it is set, unde

Re: Error: constant false is not an lvalue

2009-08-30 Thread grauzone
Jarrett Billingsley wrote: On Sun, Aug 30, 2009 at 12:24 AM, Ary Borenszweig wrote: Steven Schveighoffer escribió: On Sat, 29 Aug 2009 20:15:55 -0400, Ellery Newcomer wrote: void blah(out bool a = false){ // blah blah blah } compile time use of blah results in error. Am I doing anything w

Re: Strange calculation problem

2009-08-25 Thread grauzone
bearophile wrote: Lars T. Kyllingstad: I think the compiler should be smart enough to figure this out for itself, but until that happens you can work around it by suffixing at least one of the integer literals with LU, so the compiler interprets the entire expression as an ulong: To make thi

Re: CRTP in D?

2009-08-19 Thread grauzone
bearophile wrote: I don't know much C++. Can CRTP be used in D1 too, to improve the performance of some D1 code? http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern Why don't you just go and try? If you hit forward referencing errors when using structs, try classes with final m

Re: 'static' keyword for positional array initialization

2009-08-12 Thread grauzone
Ali Cehreli wrote: Lars T. Kyllingstad Wrote: I've tried with DMD 2.031, and I can't reproduce this. This works fine for me: int[2] static_0 = [ 1, 1 ]: int[2] static_1 = [ 1:1 ]; Where did you put the declarations? I've tried putting them at both module level and in a class, and both

Re: Pointer to method C++ style

2009-07-24 Thread grauzone
LOOKUP_TABLE[0] = Method("method1", &Component.method1); LOOKUP_TABLE[1] = Method("method2", &Component.method2); These two lines are weird. ``pragma(msg)`` shows that type of ``&method1`` is ``void function()`` while it must be ``void delegate()`` for a non-static member beca

Re: dmd crashes with "out of memory" error

2009-07-15 Thread grauzone
Trass3r wrote: Robert Fraser schrieb: File is probably too big. Remember that for every byte in your binary, DMD is likely allocating several hundred for the literal xpression object + codegen for the expression, etc., and frees very little dynamically allocated memory. So we can't even em

Re: Array slice length confusion

2009-07-09 Thread grauzone
Daniel Keep wrote: Tim Matthews wrote: Kagamin wrote: Tim Matthews Wrote: I thought a slice would behave slighty different due to some sort of meta data that is a separate area of memory so it doesn't effect D's abi. Current plan is to introduce new type - array - into the language. Do yo

Re: Should be easy

2009-06-12 Thread grauzone
Ever heard of recursion? Why don't you simply handle all types recursively? Why do you need this "array depth" stuff?

Re: Inside the switch statement

2009-06-09 Thread grauzone
BCS wrote: Hello grauzone, http://groups.google.com/group/net.lang.c/msg/66008138e07aa94c Many people (even Brian Kernighan?) have said that the worst feature of C is that switches don't break automatically before each case label. Oh god, that's from 1984, and even today we

Re: Inside the switch statement

2009-06-09 Thread grauzone
http://groups.google.com/group/net.lang.c/msg/66008138e07aa94c >Many people (even Brian Kernighan?) have said that the worst feature of C is that switches don't break automatically before each case label. Oh god, that's from 1984, and even today we're struggling with this bullshit in the mos

Re: legal identifier check

2009-05-31 Thread grauzone
Saaa wrote: Hello Saaa, static if(is(typeof({ /* code to be checked for validity goes here */ }))) ... How does that piece of code work anyways :D that checks to see if the {...} is a valid delegate literal by using is() to see if semantic checks fail. Ah, I see. Can this be done at runt

Re: Encoding problems...

2009-05-28 Thread grauzone
Robert Fraser wrote: > Jarrett Billingsley wrote: >> On Wed, May 27, 2009 at 8:55 PM, Robert Fraser >> wrote: >>> Hi all, >>> >>> Quick question: I want to use some unicode identifiers, but I get >>> "unsupported char 0xe2", both with using and not using a BOM. The characters >>> in question are t

Re: synchronized and thread

2009-05-18 Thread grauzone
reimi gibbons wrote: if i encapsulate a part of statements within function with synchronized keyword and then let says 1 thread is calling the function, then another thread try to access it, will d put the later thread to wait (sleep) until the 1st call finished it or it will signal failure to

Re: Comparing D structs

2009-05-17 Thread grauzone
Dan wrote: That sounds great, and seems like yet another reason for me to switch to D (other than the removal of header files which always seemed like a kludge). I heard that the compiler can change the padding bytes to non-null on some occasions. For example, the compiler could treat member

Re: Comparing D structs

2009-05-17 Thread grauzone
Dan wrote: Structs can't easily be compared in C because of potential 'padding' inside the struct which may (or may not) exist. I was jut wondering if D somehow gets round this, and allows something like memcmp to easily compare two structs. How about using the == operator?

Re: Who wants to have some fun memory debugging?

2009-05-12 Thread grauzone
Maybe it's time to put together an instrumented GC... Wishlist: - some way to know _when_ a collection happened (or how often) - logging of allocations (module/linenumber of allocator, size of allocation, type of allocation) - per TypeInfo allocation statistics - per module allocation statisti

Re: Who wants to have some fun memory debugging?

2009-05-12 Thread grauzone
Wild guess: there's a false pointer, that keeps one element in the list from being collected, and because the list-prev pointers are still there, all following elements won't be collected either in consequence. If I had time, I'd try two experiments: 1. before freeing everything, reset the prev

Re: 3 variant questions

2009-05-12 Thread grauzone
Dear Saaa, these varargs suck badly and you shouldn't use them. It's so simple to introduce portability errors or heisenbugs, and it's incredibly hard to get it right. You're better off with alternatives. Alternative 1: Typesafe Variadic Functions Useful if the variadic arguments should have on

Re: D input: how-to (RFC)

2009-05-11 Thread grauzone
int read(/+File inFile = stdin,+/ A...)(out A a) /+Uncommenting results in: Error: arithmetic/string type expected for value-parameter, not File+/ That would make inFile a template parameter, which obviously doesn't make sense with objects, and I guess File is an object. This should work: int r

Re: D input: how-to (RFC)

2009-05-10 Thread grauzone
Tyro[a.c.edwards] wrote: I am looking for a D version of scanf() but I'm sure there is no such thing so I tried contrived one. I am sure I missed a slew of obvious There's readf() in std.stream. I think you have to use std.cstream : din to use it with stdin. int read(/+File inFile = stdin,

Re: dmd on ubuntu installation

2009-05-10 Thread grauzone
Michael P. wrote: Michael P. Wrote: Mike Parker Wrote: Michael P. wrote: Frits van Bommel Wrote: Michael P. wrote: But when I type dmd in the terminal, I get this: mich...@ubuntu:~$ dmd bash: /usr/local/bin/dmd: Permission denied mich...@ubuntu:~$ Do you know why? Looks like you didn

Re: Resource availability: fonts

2009-05-06 Thread grauzone
http://digitalmars.com/d/1.0/expression.html#ImportExpression It returns a char[], which is a misdesign, because the loaded file can be binary data as well. I think.

Re: Resource availability: fonts

2009-05-05 Thread grauzone
Use ubyte[] fontbytes = cast(ubyte[])import("yourfont.ttf");

Re: Get the name of a function and the parameters?

2009-04-29 Thread grauzone
D". Because a D compiler that doesn't use DMD's front-end is not D compatible. Because the front end *is* the specification of the language. ...and it's full of bugs.

Re: Get the name of a function and the parameters?

2009-04-29 Thread grauzone
Jarrett Billingsley wrote: On Tue, Apr 28, 2009 at 10:23 PM, Daniel Keep wrote: That requires f to be a type, which loses you the actual names. And you cannot (last time I checked) have aliases in a tuple. Check again - tuples can be any arbitrary mix of types, expressions, and aliases. :)

Re: Get the name of a function and the parameters?

2009-04-28 Thread grauzone
Jarrett Billingsley wrote: On Sun, Apr 26, 2009 at 12:23 PM, Jacob Carlborg wrote: Is it possible to get the name of a function and the names of the function parameters? Name of a function? Yes. public template NameOfFunc(alias f) { version(LDC) const char[] NameOfFu

Re: static initialization of associative arrays

2009-04-15 Thread grauzone
What's the advantage of doing this? Having quicker startup times? Syntax. Read the first post of this thread.

Re: clone method of Object

2009-04-15 Thread grauzone
bearophile wrote: grauzone: the clone method will only copy member b, but not a or c. A *good* implementation of this function seems fit to be added to Phobos. And serialization, and a complete reflection API. Bye, bearophile

Re: clone method of Object

2009-04-15 Thread grauzone
There are two things on my side: 1. Compiler refuses to clone private attributes. I have tried gdc/gdmd/dmd_v1 in Linux. It was changed in dmd later, and now you can access private attributes by using tupleof. I don't know when exactly it was changed, but it should work at least with dmd 1.039

Re: clone method of Object

2009-04-15 Thread grauzone
Qian Xu wrote: grauzone wrote: newobject.tupleof[i] = old.tupleof[i]; If the current value of tupleof[i] is an object, the object will be referenced, won't it? Shall I write: auto elem = old.tupleof[i]; static if (is(typeof(elem) == class)) { newobject.tupleof[i] = clone

Re: clone method of Object

2009-04-15 Thread grauzone
grauzone wrote: Qian Xu wrote: Hi All, is there any (easy) way to clone an object or any other classes? --Qian Simple answer: No. Complicated answer: Yes, but you have to write it yourself. Here's a nice starting point. You can use tupleof to get all members of a class. Note that

Re: clone method of Object

2009-04-15 Thread grauzone
Qian Xu wrote: Hi All, is there any (easy) way to clone an object or any other classes? --Qian Simple answer: No. Complicated answer: Yes, but you have to write it yourself. Here's a nice starting point. You can use tupleof to get all members of a class. Note that this doesn't deal with s

Re: Indexing an associative array with a list of types

2009-04-11 Thread grauzone
What exactly are you trying to accomplish? It seems that you want to use the AA in CTFE, but it doesn't work, because using AAs with classes as keys don't work in CTFE?

Re: Indexing an associative array with a list of types

2009-04-11 Thread grauzone
Doctor J wrote: I'd like to make a compile-time constant associative array mapping a list of types to an integer: int[??] typemap; typemap[(int,float)] = 1; typemap[(long,double)] = 2; ... int t = typemap[(int,float)]; I tried playing with std.typetuple but no luck. I can get halfway there w

Re: Class templates with types determined at runtime

2009-04-07 Thread grauzone
Not sure what you're actually trying to do, but you can do this: class Container { abstract void dostuff(); } class ContainerSDgsdg(T) : Container { override void dostuff() { //can use T here } } Container bla = new ContainerSDgsdg!(int)(); //can pass aro

Re: Format.convert problme

2009-04-06 Thread grauzone
Qian Xu wrote: grauzone wrote: Check if the variable is a pointer, and if yes, dereference it: alias typeof(i) T; static if (is(T T2 : T2*)) { T2 i2 = *i; Format.convert("{}", i2); } else { Format.convert("{}", i); } Hi again, I cannot compile this code What exactly

Re: Format.convert problme

2009-04-04 Thread grauzone
Qian Xu wrote: Hi All, tango.text.convert.Format provides a nice function to convert anything to string. It works perfect except the argument is a pointer type. It will print the address of a pointer instead of its value For instance: int* i = new int; *i = 1

Re: What's the purpose of the -v1 switch?

2009-04-01 Thread grauzone
Jarrett Billingsley wrote: On Wed, Apr 1, 2009 at 12:01 PM, Trass3r wrote: I mean it can only be used with dmd 1.x compilers anyway. else if (strcmp(p + 1, "v1") == 0) { #if DMDV1 global.params.Dversion = 1; #else error("use DMD 1.0 series compilers for -v1 switch"); break

Re: About alias

2009-03-31 Thread grauzone
Trass3r wrote: Sam Hu schrieb: I am confused again this time about the key word alias when I read below tutorial: http://www.dsource.org/projects/tutorials/wiki/MetaBinarySearch Let's say this one: template bSearch(alias Match, alias Fail, alias x, A...) { const bSearch = bSearchAlg!(0,Matc

Re: dump object

2009-03-30 Thread grauzone
Qian Xu wrote: Hi All, previously I saw an article about how to dump an object with all properties. -code--- void log(T)(T obj) { static if (is(T == struct) || is(T == class)){ writef("{"); foreach(i,_;obj.tupleof) { writefln("%s : %s,", ob

Re: LPT

2009-03-25 Thread grauzone
Jarrett Billingsley wrote: On Wed, Mar 25, 2009 at 5:00 PM, Jarrett Billingsley wrote: On Wed, Mar 25, 2009 at 4:21 PM, Zarathustra wrote: Have you got any idea how to manipulate LPT port in Windows XP with D? Um, the same way you'd do it with any other language...? I mean, if you compute

Re: How to reduce compile times?

2009-03-23 Thread grauzone
Jarrett Billingsley wrote: On Sat, Mar 21, 2009 at 3:45 PM, grauzone wrote: Also, I noticed that "dsss build -full" seems to be the way to pass this flag on the command line. But the project is recompiled even when no file was modified at all. This is not good: it should only re

Re: How to reduce compile times?

2009-03-21 Thread grauzone
Brian wrote: On Sat, 21 Mar 2009 15:44:41 +0100, grauzone wrote: I'm using dsss (with dmd under Linux) to compile my project, and build/compile times are reaching unacceptable highs. out of curiosity, how much code do you actually have? im using D for something with ~12,000 lines of

Re: How to reduce compile times?

2009-03-21 Thread grauzone
I use bud, which builds everything with a single run of dmd, but uses incremental compilation. If I get linker errors, I just run my cleanup script and try again. Or add -full to bud's command line. In my case, this practically always causes linker errors. Of course I don't know why.

Re: How to reduce compile times?

2009-03-21 Thread grauzone
Jarrett Billingsley wrote: On Sat, Mar 21, 2009 at 2:50 PM, grauzone wrote: What I need is to make dsss completely recompile the project, even if only a single source file was modified. This way, no errors should occur, and it would still be faster than with oneatatime=yes. -full Sorry

Re: How to reduce compile times?

2009-03-21 Thread grauzone
Christopher Wright wrote: grauzone wrote: PS: another thing that possibly would bring a speed gain would be to make dsss compile the whole project in one run, instead of invoking a new dmd process for each source file. How do I need to change the rebuild configuration to achieve this

Re: DSSS verbose mode?

2009-03-21 Thread grauzone
The closest thing that I know is "dsss build -v"

How to reduce compile times?

2009-03-21 Thread grauzone
I'm using dsss (with dmd under Linux) to compile my project, and build/compile times are reaching unacceptable highs. What are some tips to speed up the build process? For example, I could imagine that heavy use of templates and CTFE slows the compiler down. Maybe string mixins with CTFE on th

Re: Universel toString

2009-03-20 Thread grauzone
Daniel Keep wrote: Qian Xu wrote: Hi All, I want to write an universel toString() method for debugging propose. However I cannot write in one version. The compiler says error all the time. Could someone tell me, how to write an universel one? What I want, is to convert primtive types (int, in

Re: Char[] confusing

2009-03-02 Thread grauzone
Qian Xu wrote: Lutger wrote: s[4] means the fifth element of s[] s[0..4] is a slice from the first to the fifth, but not including the fifth element. The last element in a slice is always one past the end of that slice. Thank you both. I have to do math in mind in order to keep my code corre

Re: chaining

2009-02-26 Thread grauzone
Brian wrote: I want to use a chaining system for easy setting of object attributes, which would work great for a single object, unfortunately derived classes cannot inherit the chained functions implicitly, whats the best way around this? class Base { int x; Base foo(int x_) {

Re: Dynamic Array Garbage collection

2009-02-24 Thread grauzone
Jarrett Billingsley wrote: On Tue, Feb 24, 2009 at 10:42 PM, Daniel Keep wrote: You missed the array literal. I saw that, but thought that it would be a short[] literal since it's usually the type of the first argument. Odd, it works. And properly too. Could it be because of integer promo

Re: "Symbol undefined" on interface with public getter and package setter

2009-02-23 Thread grauzone
Last time I checked I could even use "override" to... erm, override methods that had package protection. The compiler didn't even complain, and I had to find out the hard way that the method wasn't virtual.

Re: Encoding of eol in multiline wysiwyg strings

2009-02-17 Thread grauzone
Jarrett Billingsley wrote: On Tue, Feb 17, 2009 at 4:41 AM, KlausO wrote: Hello, does the D specification specify how the "end of line" is encoded when you use wysiwyg strings. Currently it seems to be '\n' on windows (And I guess it will '\n' on linux, too.). Is this the intended behaviour ?

Re: get a struct member pointer

2009-02-16 Thread grauzone
bearophile wrote: Daniel Keep: void lookup(T)(T[] s, size_t offset) { char[] text = *cast(char[]*)(cast(void*)(&s[0]) + offset); } I am learning still this topic, but can't this create an aliasing problem, as in C? http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_alias

Re: Internal error: ..\ztc\evalu8.c 2093

2009-02-11 Thread grauzone
John Reimer wrote: Hello Zarathustra, When I trying build dwt-win 3.4.1 I get the following error: Internal error: ..\ztc\evalu8.c 2093 command line: dsss build I using DSSS 0.78, Tango 0.99.7 with DMD 1.033. OS: Windows XP Any ideas? Can you try a more recent compiler... like dmd 1.037?

Re: Compare two objects

2009-02-10 Thread grauzone
Qian Xu wrote: Hi All, I want to test, if two objects are equal. The rules are as follows: 1. When both are null, it should return true. 2. When one of them is null, it should return false. 3. When both not null, then compare their values (as two strings) My test code --

Re: Time some code using Tango

2009-02-03 Thread grauzone
Jarrett Billingsley wrote: On Tue, Feb 3, 2009 at 5:54 PM, Matthias Walter wrote: Hi there, I'd like to time some functions using Tango, but only including the really used CPU-time. StopWatch and the other time functions I've found don't mind on the CPU usage, which means if I time multiple

Re: Some performance questions

2009-02-02 Thread grauzone
I agree. Of course using an interface to call a method always requires a virtual method call. It's even slower than a virtual method call, because it needs to convert the interface reference into an object reference. But he still could call the method in question directly. Implementing an int

Re: Some performance questions

2009-02-02 Thread grauzone
Jarrett Billingsley wrote: On Mon, Feb 2, 2009 at 3:11 PM, Chris Nicholson-Sauls wrote: Or he's caching some very big/complex parameters in the code he's actually writing... maybe. That said: do we have any assurance that, were the functor class tagged as 'final', the call would cease to be vir

Re: Some performance questions

2009-02-02 Thread grauzone
Jarrett Billingsley wrote: On Mon, Feb 2, 2009 at 8:31 AM, Lars Kyllingstad wrote: I have some functions for which I want to find the nicest possible combination of performance and usability. I have two suggestions as to how they should be defined. "Classic" style: real myFunction(real arg

Re: foreach/opApply is the visitor pattern

2009-02-01 Thread grauzone
BCS wrote: Correct me if I'm wrong but I thing that D's opApply is a form of the Visitor pattern where the calling function's stack frame is the visitor object. This just occurred to me. Maybe I've been missing something re the visitor pattern but I think this make for a nice, cool and easy w

Re: foreach/opApply is the visitor pattern

2009-02-01 Thread grauzone
BCS wrote: Hello Robert, BCS wrote: Correct me if I'm wrong but I thing that D's opApply is a form of the Visitor pattern where the calling function's stack frame is the visitor object. This just occurred to me. Maybe I've been missing something re the visitor pattern but I think this make f

Re: Segmentation error at the end problem (148 line program listing)

2009-01-31 Thread grauzone
Daniel Keep wrote: grauzone wrote: The garbage collector isn't guaranteed to to free and destroy an unreachable object. That's because the GC is conservative. So if you want to be sure the object's resources are freed, you have to do it explicitly. I think you have two cho

Re: Segmentation error at the end problem (148 line program listing)

2009-01-31 Thread grauzone
The garbage collector isn't guaranteed to to free and destroy an unreachable object. That's because the GC is conservative. So if you want to be sure the object's resources are freed, you have to do it explicitly. I think you have two choices: 1. Remove close() from the destructor, and call cl

Re: Segmentation error at the end problem (148 line program listing)

2009-01-30 Thread grauzone
Charles Hixson wrote: I replaced BlockFile.close with: void close() { if (bf !is null) delete bf;//bf.close; bf = null; } But that didn't alter the segmentation fault. (Did you try it under D1 or D2?) Your destructor calls close(), and close() accesses the refe

Accessing private class members with tupleof

2009-01-29 Thread grauzone
Is it legal to access private members of a class using tupleof, when normal access would be illegal? It is not really clear from the D1.0 specification: > The .tupleof property returns an ExpressionTuple of all the fields in > the class, excluding the hidden fields and the fields in the base >

Re: Prevent default-initialised struct

2009-01-28 Thread grauzone
I think it would really suck to introduce special cases to forbid default initialization of structs. And assuming T was the type of the struct, what would T.init do? Or typeid(T).init()? Use a class instead. If you really need a struct, you could use a private field, that signals if the struc