Re: Clear big AAs
useo: Is there anything I forgot to consider? If the key and values are primitive values or structs of primitive values then you may try another AA implementation that doesn't use the GC. Bye, bearophile I tried some different implementations and I also reduced the size of my arrays without any success :(. It always drops down to 1 FPS for 1 second and after that it runs for some seconds normal until next 1 FPS-second. I also tried to do the work within a separate thread, also without success. My current code looks like: toRender.clear(); toRender = null; for (int y = pFromY; y pToY y pTiles.length; y++) { for (int x = pFromX; x pToX x pTiles[y].length; x++) { toRender[pTiles[y][x].texture] ~= pTiles[y][x]; } } toRender is my AA which contains the textures as key (instances of my class Texture) and the tiles (position of them) as values. When I remove the first two lines (clear and set null) it doesn't drops down to 1 FPS, it runs normal. I hope anyone know a solution :)
Re: Clear big AAs
== Auszug aus David Nadlinger (s...@klickverbot.at)'s Artikel I realize that this might sound strange, but try setting myAA to null after clear(), this should fix the crash. David On 5/31/11 4:00 PM, useo wrote: Hi, I'm trying to clear big associative arrays, but I always get an object error - what I currently doing is: private string[uint] myAA; void main() { fill(myAA); myAA.clear(); fill(myAA); // object.Error: Access Violation } void fill(string[uint] aa) { for (uint i = 0; i 10_000_000_000; i++) { myAA[i] = std.conv.to!(string)(i); } } I already saw the bug report at http://www.digitalmars.com/d/ archives/ digitalmars/D/bugs/ Issue_5683_New_Calling_.clear_on_a_fresh_associative_array_causes_subsequent_segfault_28632.html and I'm also using 2.052 - as I saw at the change-log of 2.053 it's also unfixed. So... is there any solution to clear associative arrays without memory leaking? Thanks a lot, I solved it by using pGraphics.clear(); pGraphics = null; // pGraphics.rehash(); I thought this'll solve my problem, but it doesn't... I've to fill my AA every 500 ms with around 250 values (in principle much less than 10_000_000_000). When I start my application (in this context, my game), it works as needed (around 2000 fps/s) but after some seconds, the fps-rate drops down to 1/s and back to normal (and again, and again...). When I remove the command to clear the array, it works without dropping down to 1 fps. I this case I can't update my screen as needed. I also tried to delete the class instance which contains the array and create an new but it's the same as before (it drops down to 1 fps). Is there anything I forgot to consider?
Clear big AAs
Hi, I'm trying to clear big associative arrays, but I always get an object error - what I currently doing is: private string[uint] myAA; void main() { fill(myAA); myAA.clear(); fill(myAA); // object.Error: Access Violation } void fill(string[uint] aa) { for (uint i = 0; i 10_000_000_000; i++) { myAA[i] = std.conv.to!(string)(i); } } I already saw the bug report at http://www.digitalmars.com/d/archives/ digitalmars/D/bugs/ Issue_5683_New_Calling_.clear_on_a_fresh_associative_array_causes_subsequent_segfault_28632.html and I'm also using 2.052 - as I saw at the change-log of 2.053 it's also unfixed. So... is there any solution to clear associative arrays without memory leaking?
Interface/abstract constructors
Hey guys, is there any chance to create an abstract constructor like: abstract class ABC { abstract this(); } DMD always says ...this non-virtual functions cannot be abstract - when I use an interface like: interface ABC { this(); } I get a similar error: ...constructors, destructors, postblits, invariants, unittests, new and delete functions are not allowed in interface ABC Is there any solution or is it possible to create such inheritances in DMD?
Re: enum with classes/structs
== Auszug aus Jonathan M Davis (jmdavisp...@gmx.com)'s Artikel On Thursday, March 10, 2011 11:28:04 bearophile wrote: useo: is it possible to declare a enum where all entries are instances of a class (or struct), like the following: I don't think so. Enums are compile-time constants. This code doesn't compile: class A { this(uint i) {} } enum myEnum : A { entry1 = new A(0), entry2 = new A(1) } void main() {} It's important to understand that in D OOP and procedural/C- style features are often separated. typedef didn't work well with OOP. Don't mix things that are not meant to be mixed. There's absolutely nothing wrong with mixing enum with OOP. An enum is simply an enumeration of values. There's absolutely nothing wrong with those values being of struct or class types. The only restrictions there are problems with the implementation. TDPL even gives examples of enum structs. They currently work when you only have one value in the enum, but fail when you have multiple ( http://d.puremagic.com/issues/show_bug.cgi?id=4423 ). If/When classes work with CTFE, then you should be able to haveenums of class objects. There's nothing about enums which are C or procedural-specific. Java has object- oriented enums which are quite powerful. And aside from the current implementation issues, D's enums are even more powerful because they allow _any_ type and so can be either primitive types or user-defined types like you'd have in Java. enums don't care one way or another about OOP. They're just a set of values that have to be ordered and be known at compile time. - Jonathan M Davis Okay, thanks - I'll hope the bug will be solved. I'm absolution right here with you, the enumerations of Java are very use- and powerful.
Multiple opCall's
Hey guys, I've a small problem implementing multiple opCall()-methods. At first, I've the following interface: interface Invoker { void opCall(uint i); } ... and an abstract class which inherits from the Invoker-interface like the following: abstract class AbstractInvoker : Invoker { private int myInt; override void opCall(uint i) { /** do nothing */ } void opCall() { opCall(myInt); } } I know... I can remove the opCall(uint i) from the interface, but it's needed for some other classes which implements this method. For those classes the opCall(uint i)-method is needed. But... when I now declare a class like this: class InvokableClass : AbstractInvoker { override void opCall(uint i) { // do something } } and do the following: void main(string[] args) { InvokableClass() ic = new InvokeableClass(); ic(); } I always get the following errors: Error: function InvokableClass.opCall (uint i) is not callable using argument types (). Error: expected 1 function arguments, not 0 But I think opCall() is implemented in the abstract class and should be callable using opCall() instead using opCall(uint i)?
Re: Multiple opCall's
== Auszug aus Mafi (m...@example.org)'s Artikel Am 21.02.2011 11:18, schrieb useo: Hey guys, I've a small problem implementing multiple opCall()-methods. At first, I've the following interface: interface Invoker { void opCall(uint i); } ... and an abstract class which inherits from the Invoker- interface like the following: abstract class AbstractInvoker : Invoker { private int myInt; override void opCall(uint i) { /** do nothing */ } In an abstract class you can just leave this out. The inheriting class will then be checked to implement this. void opCall() { opCall(myInt); } } I know... I can remove the opCall(uint i) from the interface, but it's needed for some other classes which implements this method. For those classes the opCall(uint i)-method is needed. But... when I now declare a class like this: class InvokableClass : AbstractInvoker { override void opCall(uint i) { // do something } } and do the following: void main(string[] args) { InvokableClass() ic = new InvokeableClass(); ic(); } I always get the following errors: Error: function InvokableClass.opCall (uint i) is not callable using argument types (). Error: expected 1 function arguments, not 0 But I think opCall() is implemented in the abstract class and should be callable using opCall() instead using opCall(uint i)? Overriding one opCall shadows all other opCalls inherited from the base class. This behaviour is like with any method. Write: override void opCall() { super.opCall(); } to forward to the base class method. AFAIK it's an anti-hijacking machanism. Okay, thanks... this helped a lot!
Re: Template for function or delegate (nothing else)
I implemented all I wanted and it works perfectly ;). But I'm using the if (is(T == delegate) || is(T == function))- statement in another class/template. class Example(T) if (is(T == delegate) || is(T == function)) { ... } Now, when I declare Example!(void function()) myVar; I always get: Error: template instance Example!(void function()) does not match template declaration Example(T) if (is(T == delegate) || is(T == function)) Error: Example!(void function()) is used as a type When I declare myVar as Example!(function), I get some other errors. What's wrong with my code?
Re: Template for function or delegate (nothing else)
== Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel On Thu, 10 Feb 2011 09:09:03 -0500, useo u...@start.bg wrote: I implemented all I wanted and it works perfectly ;). But I'm using the if (is(T == delegate) || is(T == function))- statement in another class/template. class Example(T) if (is(T == delegate) || is(T == function)) { ... } Now, when I declare Example!(void function()) myVar; I always get: Error: template instance Example!(void function()) does not match template declaration Example(T) if (is(T == delegate) || is(T == function)) Error: Example!(void function()) is used as a type When I declare myVar as Example!(function), I get some other errors. What's wrong with my code? Please post a full example that creates the error. From that error message, it appears that your code is correct, but I'd have to play with a real example to be sure. -Steve I created a complete, new file with the following code: module example; void main(string[] args) { Example!(void function()) myVar; } class Example(T) if (is(T == delegate) || is(T == function)) { } And what I get is: example.d(4): Error: template instance Example!(void function()) does not match template declaration Example(T) if (is(T == delegate) || is (T == function)) example.d(4): Error: Example!(void function()) is used as a type I'm using the current stable version 2.051.
Re: Template for function or delegate (nothing else)
== Auszug aus useo (u...@start.bg)'s Artikel == Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel On Thu, 10 Feb 2011 09:09:03 -0500, useo u...@start.bg wrote: I implemented all I wanted and it works perfectly ;). But I'm using the if (is(T == delegate) || is(T == function))- statement in another class/template. class Example(T) if (is(T == delegate) || is(T == function)) { ... } Now, when I declare Example!(void function()) myVar; I always get: Error: template instance Example!(void function()) does not match template declaration Example(T) if (is(T == delegate) || is(T == function)) Error: Example!(void function()) is used as a type When I declare myVar as Example!(function), I get some other errors. What's wrong with my code? Please post a full example that creates the error. From that error message, it appears that your code is correct, but I'd have to play with a real example to be sure. -Steve I created a complete, new file with the following code: module example; void main(string[] args) { Example!(void function()) myVar; } class Example(T) if (is(T == delegate) || is(T == function)) { } And what I get is: example.d(4): Error: template instance Example!(void function()) does not match template declaration Example(T) if (is(T == delegate) || is (T == function)) example.d(4): Error: Example!(void function()) is used as a type I'm using the current stable version 2.051. I noticed, that this error only occurs when I use function as template-type. When I use Example!(void delegate()) myVar; it compiles without any error. With function - Example!(void function()) myVar; I get the error(s) above.
Re: Template for function or delegate (nothing else)
== Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel On Thu, 10 Feb 2011 09:48:14 -0500, useo u...@start.bg wrote: I created a complete, new file with the following code: module example; void main(string[] args) { Example!(void function()) myVar; } class Example(T) if (is(T == delegate) || is(T == function)) { } And what I get is: example.d(4): Error: template instance Example!(void function()) does not match template declaration Example(T) if (is(T == delegate) || is (T == function)) example.d(4): Error: Example!(void function()) is used as a type I'm using the current stable version 2.051. Found this invalid bug. Apparently, this is expected (!) behavior: http://d.puremagic.com/issues/show_bug.cgi?id=3464 So use this instead: class Example(T) if (is(T == delegate) || is(typeof(*T.init) == function)) Ugly, I know, but I guess that's what we got to work with. -Steve Yes, looks a bit unusual but it works, thanks!
Template for function or delegate (nothing else)
Is it possible to create a template which only accepts functions or delegates like this example: class Example(T : void function()) { // or ..(T : void delegate()).. T callback; } Where T is a function or a delegate... Thanks for every suggestion!
Re: Template for function or delegate (nothing else)
== Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel On Wed, 09 Feb 2011 14:35:42 -0500, useo u...@start.bg wrote: Is it possible to create a template which only accepts functions or delegates like this example: class Example(T : void function()) { // or ..(T : void delegate ()).. T callback; } Where T is a function or a delegate... Thanks for every suggestion! class Example(T) if (is(T == delegate) || is(T == function)) { T callback; } -Steve Wow, works great - THANKS :)
Re: Template for function or delegate (nothing else)
== Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel On Wed, 09 Feb 2011 14:59:33 -0500, useo u...@start.bg wrote: == Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel On Wed, 09 Feb 2011 14:35:42 -0500, useo u...@start.bg wrote: Is it possible to create a template which only accepts functions or delegates like this example: class Example(T : void function()) { // or ..(T : void delegate ()).. T callback; } Where T is a function or a delegate... Thanks for every suggestion! class Example(T) if (is(T == delegate) || is(T == function)) { T callback; } -Steve Is there any chance to do the same for methods like: void example(T)() { } ... something like: void bindEvent(T)(if (is(T == delegate) || is(T == function))) ()... Yes, but you have the order mixed up. void bindEvent(T)() if (is...) In general form, a template constraint goes after the declaration, but before the body of the template. -Steve Ah, okay... I already tried the if-statement after the declaration but I always got an error like this: ... semicolon expected following function declaration I just removed ( and ) from the if-statement and it's working, thanks in again!
Re: Template for function or delegate (nothing else)
I just have a problem with my variables. For example... my class/template just looks like: class Example(T) if (is(T == delegate) || is(T == function)) { T callback; void setCallback(T cb) { callback = cb; } } This means that I need variables like Example!(void function()) myVariable. But is there any possibility to use variables like Example myVariable? The template declaration only defines the type of a callback and perhaps one method-declaration nothing else. I already tried Example!(void*) because delegates and functions are void pointers but I always get an error. I hope there is any way to do this.
Re: Template for function or delegate (nothing else)
== Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel On Wed, 09 Feb 2011 16:14:04 -0500, useo u...@start.bg wrote: I just have a problem with my variables. For example... my class/template just looks like: class Example(T) if (is(T == delegate) || is(T == function)) { T callback; void setCallback(T cb) { callback = cb; } } This means that I need variables like Example!(void function()) myVariable. But is there any possibility to use variables like Example myVariable? The template declaration only defines the type of a callback and perhaps one method-declaration nothing else. I already tried Example!(void*) because delegates and functions are void pointers but I always get an error. I hope there is any way to do this. If I understand you correctly, you don't want to declare the type of T when instantiating the template? This is not possible, templates must have all parameters defined at instantiation time. If you just want a shorter thing to type for Example!(void function ()), you can do: alias Example!(void function()) MyType; MyType myVariable; -Steve Yes, right, I don't want declare the template-type. Nevertheless... thanks
Re: Template for function or delegate (nothing else)
== Auszug aus bearophile (bearophileh...@lycos.com)'s Artikel useo: I just have a problem with my variables. For example... my class/template just looks like: class Example(T) if (is(T == delegate) || is(T == function)) { T callback; void setCallback(T cb) { callback = cb; } } This means that I need variables like Example!(void function ()) myVariable. But is there any possibility to use variables like Example myVariable? D is not the SML language, templates are just placeholders. If you don't instantiate a template, you have only a symbol. Example is only assignable to an alias (and in past, to a typedef): alias Example Foo; The template declaration only defines the type of a callback and perhaps one method-declaration nothing else. I already tried Example!(void*) because delegates and functions are void pointers but I always get an error. I hope there is any way to do this. I don't yet understand what you are trying to do. Other notes: - What if your T is a functor (a callable class/struct/union instance that defined opCall)? - sizeof of a function pointer is 1 CPU word, while a delegate is 2 CPU words (and a delegate clojure has stuff on the heap too, sometimes). Bye, bearophile Idea is the following: class Example(T) if (is(T == delegate) || is(T == function)) { T callback; void setCallback(T cb) { callback = cb; } void opCall() { callback(); } } other file: import example; private { Example variable; } void setExampleVariable(Example ex) { variable = ex; } void callCurrentExampleVariable() { variable(); }
Re: Template for function or delegate (nothing else)
== Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel On Wed, 09 Feb 2011 16:41:25 -0500, useo u...@start.bg wrote: == Auszug aus bearophile (bearophileh...@lycos.com)'s Artikel useo: I just have a problem with my variables. For example... my class/template just looks like: class Example(T) if (is(T == delegate) || is(T == function)) { T callback; void setCallback(T cb) { callback = cb; } } This means that I need variables like Example!(void function ()) myVariable. But is there any possibility to use variables like Example myVariable? D is not the SML language, templates are just placeholders. If you don't instantiate a template, you have only a symbol. Example is only assignable to an alias (and in past, to a typedef): alias Example Foo; The template declaration only defines the type of a callback and perhaps one method-declaration nothing else. I already tried Example!(void*) because delegates and functions are void pointers but I always get an error. I hope there is any way to do this. I don't yet understand what you are trying to do. Other notes: - What if your T is a functor (a callable class/struct/union instance that defined opCall)? - sizeof of a function pointer is 1 CPU word, while a delegate is 2 CPU words (and a delegate clojure has stuff on the heap too, sometimes). Bye, bearophile Idea is the following: class Example(T) if (is(T == delegate) || is(T == function)) { T callback; void setCallback(T cb) { callback = cb; } void opCall() { callback(); } } other file: import example; private { Example variable; } void setExampleVariable(Example ex) { variable = ex; } void callCurrentExampleVariable() { variable(); } I don't think you want templates. What you want is a tagged union (and a struct is MUCH better suited for this): // untested! struct Example { private { bool isDelegate; union { void function() fn; void delegate() dg; } } void setCallback(void function() f) { this.fn = f; isDelegate = false;} void setCallback(void delegate() d) { this.dg = d; isDelegate = true;} void opCall() { if(isDelegate) dg(); else fn(); } } -Steve Looks really interesting and seems to work. Thanks in advance!
Re: dmd compile with imported modules
I just compiled xfbuild on 32bit ubuntu, but when I try to compile, I get the following error: Build failed: /usr/include/d/dmd/druntime/import/core/stdc/errno.o: Invalid cross-device link. Does anyone know how to solve this problem?
Re: dmd compile with imported modules
I solved the problem by copying the source files from my shared vm- folder to my desktop in my vm.
Re: dmd compile with imported modules
rdmd has some problems with my lib-files. Instead of rdmd I just tried xfbuild and it works great on windows, but as I can see there is no linux 32 bit version which I would like to use?!
dmd compile with imported modules
Hey guys, I've the following problem... when I write a simple class, for example: ... module myclasses.exampleClass; class exampleClass { void writeHelloWorld() { writeln(Hello World); } And import myclasses.exampleClass in the following: ... module mainfile; import myclasses.exampleClass; void main(string[] args) { exampleClass ec = new exampleClass(); ec.writeHelloWorld(); } ... I always have to compile the mainfile-module with dmd mainfile.d myclasses/exampleClass.d because of the obj-files. My projects are always growing and I don't want list all 100 or more classes/files in the command line. Is there any possibility to automatically import, compile and link all the files with a short command? Thanks in advance!
String to enum
Hi, does anyone know how I can cast a string to an enum which also contains strings? For example: enum MyENUM : string { x = 123 y = 456 z = 789 } ... string myString = X; to!(MyENUM)(myString); // Error: cannot implicitly convert expression (_adDupT(( D12TypeInfo_Aya6__initZ),s)) of char[]... cast(MyENUM) myString; // Does work, but it seems that other values like MyENUM.a, MyENUM.b... are also successfully casted to MyENUM but MyENUM doesn't contain a, b or similiar invalid/undefined values. I hope anyone can solve the problem... thanks.