Re: Using dub

2015-01-27 Thread Joel via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 07:44:12 UTC, Rikki Cattermole wrote: On 27/01/2015 8:40 p.m., Joel wrote: On Tuesday, 27 January 2015 at 07:25:18 UTC, Rikki Cattermole wrote: On 27/01/2015 8:03 p.m., Joel wrote: I'm having trouble using dub. Nothing seems to work (-h works though). I would lik

Re: Using dub

2015-01-27 Thread Joel via Digitalmars-d-learn
Oope, yeah, and it ran.

Re: Virtual functions and inheritance

2015-01-27 Thread Daniel Kozák via Digitalmars-d-learn
V Tue, 27 Jan 2015 04:38:57 + David Monagle via Digitalmars-d-learn napsáno: > Hi guys, > > I'm a former C++ developer and really enjoying working with D > now. I have a question that I hope some of you may be able to > answer. > > class Parent { >@property string typeName() { >

Re: core.exception.InvalidMemoryOperationError@(0)

2015-01-27 Thread ketmar via Digitalmars-d-learn
On Tue, 27 Jan 2015 06:46:20 +, Bayan Rafeh wrote: > This is the first serious project I do with D and now you're lost to other C-like languages, methinks. ;-) signature.asc Description: PGP signature

Re: static class vs. static struct

2015-01-27 Thread ref2401 via Digitalmars-d-learn
For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I've got a question. Why do Phobos guys use struct or static struct for or singleton pattern implementation? Why don't use sta

Re: Array List object?

2015-01-27 Thread bearophile via Digitalmars-d-learn
Gan: //Initializing the array tiles = new SBTile[](0); This is often useless. //Clearing the array tiles = []; This doesn't "clear" the array, it rebinds it to a null pointer. Bye, bearophile

Re: static class vs. static struct

2015-01-27 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I've got a question. Why do Phobos guys use struct or static struc

Re: Array List object?

2015-01-27 Thread bearophile via Digitalmars-d-learn
And it's named "dynamic array", instead of "Array List object", it's not a class instance. Bye, bearophile

Re: static class vs. static struct

2015-01-27 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 09:36:49 UTC, Daniel Kozak wrote: On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I

Re: static class vs. static struct

2015-01-27 Thread ketmar via Digitalmars-d-learn
On Tue, 27 Jan 2015 09:40:08 +, Daniel Kozak wrote: > import std.stdio; > import std.conv; > > struct S { > @disable this(); > } > > final class C { > } > > void main() { > writeln(C.sizeof); > writeln(S.sizeof); > } blind guess: vmt with "toString()" from Object? ;-) signa

Re: Virtual functions and inheritance

2015-01-27 Thread via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 08:19:46 UTC, Daniel Kozák wrote: You can use this T: class Parent { @property string typeName(this T)() { return T.stringof; } } class Child : Parent { } void main() { auto p = new Parent; auto c = new Child; assert(p.typeName == "Pa

Re: Virtual functions and inheritance

2015-01-27 Thread Baz via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 08:19:46 UTC, Daniel Kozák wrote: You can use this T: class Parent { @property string typeName(this T)() { return T.stringof; } } class Child : Parent { } void main() { auto p = new Parent; auto c = new Child; assert(p.typeName == "Pa

Re: Virtual functions and inheritance

2015-01-27 Thread bearophile via Digitalmars-d-learn
Baz: doesn't work. And similarly to the the orginal post: I suggest to read some D documentation first, and program later. Bye, bearophile

Re: Virtual functions and inheritance

2015-01-27 Thread Tobias Pankrath via Digitalmars-d-learn
- class Bar { static T construct(this T, A...)(A a) { return new T(a); } } I think it's a bug that you can use a template this parameter (this T) on a static member function without a direct compilation error. - class Bar { static typeof(this) construct(A

Classical bug

2015-01-27 Thread Fyodor Ustinov via Digitalmars-d-learn
Hi! I thought at least in safe mode this code will not compile or I get warning: byte[] func() @safe { byte[1024] buffer; return buffer[0..3]; } void main() { auto b = func(); b[0] = 1; } But no any error. Dlang do not catch this? WBR, Fyodor.

Re: Classical bug

2015-01-27 Thread Vladimir Panteleev via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 11:41:21 UTC, Fyodor Ustinov wrote: byte[] func() @safe { byte[1024] buffer; return buffer[0..3]; } void main() { auto b = func(); b[0] = 1; } In 2.067, this is an error: test.d(4,9): Error: escaping reference to local variable buffer

Re: Classical bug

2015-01-27 Thread Vladimir Panteleev via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 12:01:11 UTC, Fyodor Ustinov wrote: On Tuesday, 27 January 2015 at 11:51:43 UTC, Vladimir Panteleev wrote: In 2.067, this is an error: test.d(4,9): Error: escaping reference to local variable buffer Always or only in safe mode? Always. But the check seems very

Re: Classical bug

2015-01-27 Thread Fyodor Ustinov via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 11:51:43 UTC, Vladimir Panteleev wrote: In 2.067, this is an error: test.d(4,9): Error: escaping reference to local variable buffer Always or only in safe mode?

Re: Classical bug

2015-01-27 Thread bearophile via Digitalmars-d-learn
Vladimir Panteleev: But the check seems very simple, and is easily circumvented. This compiles: byte[] func() { byte[1024] buffer; auto p = buffer[0..3]; return p; } I guess such bugs will be detected (in safe code only!) after the implementation of: http://wiki.dlang.org/DIP69 Currently

Re: Classical bug

2015-01-27 Thread Fyodor Ustinov via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 12:02:59 UTC, Vladimir Panteleev wrote: Always. But the check seems very simple, and is easily circumvented. This compiles: byte[] func() { byte[1024] buffer; auto p = buffer[0..3]; return p; } I think this is the first step of a long and difficult way. by

I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread Gan via Digitalmars-d-learn
I feel like the only way I can get better right now is if someone with more knowledge can give me some advice on the code I have written. Here's the link: http://cl.ly/0s0Q1L1S3v0E How can I make it use less CPU/RAM? (Most code is in the Misc/SpaceBackground.d)

Re: Array List object?

2015-01-27 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 27, 2015 at 07:18:22AM +, Gan via Digitalmars-d-learn wrote: [...] > Okay now I'm very confused. When I have my program fully hidden behind > another window, my ram usage goes up without going down. Which my > program is partly visible it goes up a few mb then returns to the past >

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread bearophile via Digitalmars-d-learn
Gan: How can I make it use less CPU/RAM? Most tiny classes probably should be structs. More generally, use a struct every time you don't need a class. You can start with those two: struct SBRange { double left = 0.0, right = 0.0, top = 0.0, bottom = 0.0; } struct Point(T) { T x, y

Re: static class vs. static struct

2015-01-27 Thread Piotrek via Digitalmars-d-learn
On Monday, 26 January 2015 at 21:55:19 UTC, anonymous wrote: On Monday, 26 January 2015 at 21:33:10 UTC, Piotrek wrote: On Monday, 26 January 2015 at 14:11:32 UTC, bearophile wrote: Non-static structs/classes have an extra pointer. Bye, bearophile Since when structs have an extra pointer? Ma

Re: static class vs. static struct

2015-01-27 Thread Artur Skawina via Digitalmars-d-learn
On 01/27/15 10:40, Daniel Kozak via Digitalmars-d-learn wrote: > On Tuesday, 27 January 2015 at 09:36:49 UTC, Daniel Kozak wrote: >> On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: >>> For several times I've met struct(or static struct) usage in Phobos for >>> singleton pattern impleme

Re: static class vs. static struct

2015-01-27 Thread Piotrek via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I've got a question. Why do Phobos guys use struct or static struc

Re: static class vs. static struct

2015-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2015 08:58 AM, Piotrek wrote: Nice list. :) > 1. static variable > > struct A{int a} // no static before declaration > static A s; //note that static is used for struct variable storage class > (lifetime) > > static int b; > etc. > > 2. static declaration > > static struct A{int a}; //s

Re: static class vs. static struct

2015-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2015 08:33 AM, Piotrek wrote: >> Non-static means nested. > > Hmm,this can be misleading. Nesting in structs doesn't introduce context > pointer. You must be thinking of structs nested inside user-defined types. Structs that are nested inside functions do have the context pointer. Al

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread Gan via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 15:45:47 UTC, bearophile wrote: Gan: How can I make it use less CPU/RAM? Most tiny classes probably should be structs. More generally, use a struct every time you don't need a class. You can start with those two: struct SBRange { double left = 0.0, right

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread bearophile via Digitalmars-d-learn
Gan: Is there some special stuff I gotta do extra with structs? Do they need manually allocated and released? Most of your usages of tiny structs should be by value. So just keep in mind they are values. Even when you iterate with a foreach on a mutable array of them :-) On a second quest

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread Gan via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 19:26:12 UTC, bearophile wrote: Gan: Is there some special stuff I gotta do extra with structs? Do they need manually allocated and released? Most of your usages of tiny structs should be by value. So just keep in mind they are values. Even when you iterate wit

About variant

2015-01-27 Thread bioinfornatics via Digitalmars-d-learn
Dear that do a lot time wehere I not used std.variant. i would like to hide extra cast from user by using a generic ctor import std.variant; struct Alpha { Variant something; this(T)(T v){ something = cast(Variant)v; } } void main(){

Re: About variant

2015-01-27 Thread bioinfornatics via Digitalmars-d-learn
I can do this import std.variant; struct Alpha { Variant something; this(Variant v){ something = v; } static Alpha build(T)(T v){ return Alpha( cast(Variant)v ); } } void main(){ auto a = A

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread Gan via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 19:59:08 UTC, Gan wrote: On Tuesday, 27 January 2015 at 19:26:12 UTC, bearophile wrote: Gan: Is there some special stuff I gotta do extra with structs? Do they need manually allocated and released? Most of your usages of tiny structs should be by value. So jus

Re: About variant

2015-01-27 Thread Justin Whear via Digitalmars-d-learn
On Tue, 27 Jan 2015 20:46:59 +, bioinfornatics wrote: > void main(){ > auto a = Alpha!(int)( 6); > auto b = Alpha!(string)( "hello"); The Alpha struct is not a template, only the constructor is. Remove the explicit instantiations and IFTI does the work: > void main(){ > au

Print to Win Printer

2015-01-27 Thread Paul via Digitalmars-d-learn
How do I print to a Windows printer from a console program? Thanks for your assistance.

Re: static class vs. static struct

2015-01-27 Thread Piotrek via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 18:24:29 UTC, Ali Çehreli wrote: On 01/27/2015 08:33 AM, Piotrek wrote: >> Non-static means nested. > > Hmm,this can be misleading. Nesting in structs doesn't introduce context > pointer. You must be thinking of structs nested inside user-defined types. Structs t

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread Rikki Cattermole via Digitalmars-d-learn
On 28/01/2015 9:59 a.m., Gan wrote: On Tuesday, 27 January 2015 at 19:59:08 UTC, Gan wrote: On Tuesday, 27 January 2015 at 19:26:12 UTC, bearophile wrote: Gan: Is there some special stuff I gotta do extra with structs? Do they need manually allocated and released? Most of your usages of tin

Re: static class vs. static struct

2015-01-27 Thread Piotrek via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 18:18:02 UTC, Ali Çehreli wrote: On 01/27/2015 08:58 AM, Piotrek wrote: Nice list. :) > 1. static variable > > struct A{int a} // no static before declaration > static A s; //note that static is used for struct variable storage class > (lifetime) > > static int b;

Re: About variant

2015-01-27 Thread bioinfornatics via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 21:00:16 UTC, Justin Whear wrote: On Tue, 27 Jan 2015 20:46:59 +, bioinfornatics wrote: void main(){ auto a = Alpha!(int)( 6); auto b = Alpha!(string)( "hello"); The Alpha struct is not a template, only the constructor is. Remove the expli

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread Gan via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 21:36:51 UTC, Rikki Cattermole wrote: On 28/01/2015 9:59 a.m., Gan wrote: On Tuesday, 27 January 2015 at 19:59:08 UTC, Gan wrote: On Tuesday, 27 January 2015 at 19:26:12 UTC, bearophile wrote: Gan: Is there some special stuff I gotta do extra with structs? Do t

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread Gan via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 22:30:13 UTC, Gan wrote: On Tuesday, 27 January 2015 at 21:36:51 UTC, Rikki Cattermole wrote: On 28/01/2015 9:59 a.m., Gan wrote: On Tuesday, 27 January 2015 at 19:59:08 UTC, Gan wrote: On Tuesday, 27 January 2015 at 19:26:12 UTC, bearophile wrote: Gan: Is ther

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread Rikki Cattermole via Digitalmars-d-learn
On 28/01/2015 11:30 a.m., Gan wrote: On Tuesday, 27 January 2015 at 21:36:51 UTC, Rikki Cattermole wrote: On 28/01/2015 9:59 a.m., Gan wrote: On Tuesday, 27 January 2015 at 19:59:08 UTC, Gan wrote: On Tuesday, 27 January 2015 at 19:26:12 UTC, bearophile wrote: Gan: Is there some special stu

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread Rikki Cattermole via Digitalmars-d-learn
On 28/01/2015 11:39 a.m., Gan wrote: On Tuesday, 27 January 2015 at 22:30:13 UTC, Gan wrote: On Tuesday, 27 January 2015 at 21:36:51 UTC, Rikki Cattermole wrote: On 28/01/2015 9:59 a.m., Gan wrote: On Tuesday, 27 January 2015 at 19:59:08 UTC, Gan wrote: On Tuesday, 27 January 2015 at 19:26:12

Re: vibe.d error

2015-01-27 Thread Phil via Digitalmars-d-learn
Bumping as it's still not possible to install lib event via dub. On Sunday, 25 January 2015 at 17:41:38 UTC, Phil wrote: dub init vibe.d cd dub Results in Fetching libevent 2.0.1+2.0.16... Error executing command upgrade: Failed to download http://code.dlang.org/packages/libevent/2.0.1%252B

Re: About variant

2015-01-27 Thread ketmar via Digitalmars-d-learn
On Tue, 27 Jan 2015 21:55:37 +, bioinfornatics wrote: > On Tuesday, 27 January 2015 at 21:00:16 UTC, Justin Whear wrote: >> On Tue, 27 Jan 2015 20:46:59 +, bioinfornatics wrote: >> >>> void main(){ >>> auto a = Alpha!(int)( 6); >>> auto b = Alpha!(string)( "hello"); >> >> The Alpha

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread Gan via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 22:42:25 UTC, Rikki Cattermole wrote: On 28/01/2015 11:39 a.m., Gan wrote: On Tuesday, 27 January 2015 at 22:30:13 UTC, Gan wrote: On Tuesday, 27 January 2015 at 21:36:51 UTC, Rikki Cattermole wrote: On 28/01/2015 9:59 a.m., Gan wrote: On Tuesday, 27 January 201

Re: static class vs. static struct

2015-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2015 01:44 PM, Piotrek wrote: > Let me here thank for your book I am glad that it is useful. > which I've been reading for some time. Me too! I browsed the index section to remember the other uses of 'static'. :) Ali

Re: static class vs. static struct

2015-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2015 01:33 PM, Piotrek wrote: > On Tuesday, 27 January 2015 at 18:24:29 UTC, Ali Çehreli wrote: >> On 01/27/2015 08:33 AM, Piotrek wrote: >> >> >> Non-static means nested. >> > >> > Hmm,this can be misleading. Nesting in structs doesn't >> introduce context >> > pointer. Oh, I misread w

Re: Using dub

2015-01-27 Thread Joel via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 08:08:19 UTC, Joel wrote: Oope, yeah, and it ran. Thanks Rikki, I wiped off the dub installation. Now, no errors. The small program worked too. I don't now how to set up the dub executable to work with out doing stuff like this - '../dub' (Mac OS 10.10.1) Jo

Re: Using dub

2015-01-27 Thread Joel via Digitalmars-d-learn
On Wednesday, 28 January 2015 at 00:34:13 UTC, Joel wrote: On Tuesday, 27 January 2015 at 08:08:19 UTC, Joel wrote: Oope, yeah, and it ran. Thanks Rikki, I wiped off the dub installation. Now, no errors. The small program worked too. Actually I got this with dlangui, (I followed the instruc

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread FG via Digitalmars-d-learn
On 2015-01-27 at 23:39, Gan wrote: I commented out some stuff and it appears my massive memory consumption comes from my tile.redraw function: ... Would you know why this is using hundreds of mb of rams? Looks OK, so probably it is not the cause by itself. I would add a piece of code to SpaceB

Re: Cached Incremental Updates of DUB Builds

2015-01-27 Thread Nordlöw
On Monday, 26 January 2015 at 22:33:21 UTC, Nordlöw wrote: Is there a way to tell DUB to compile all its sources as separate objects which are then fed to ld. And I don't want DMD to recompile every line in my project if I change only of them...and yes most of my cross-module interfaces are u

Re: Cached Incremental Updates of DUB Builds

2015-01-27 Thread data man via Digitalmars-d-learn
Try it: https://github.com/gecko0307/Cook2 On Monday, 26 January 2015 at 22:33:21 UTC, Nordlöw wrote: Is there a way to tell DUB to compile all its sources as separate objects which are then fed to ld. My project has grown beyound 10k lines of code. And I don't want DMD to recompile every lin

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread Vladimir Panteleev via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 22:39:31 UTC, Gan wrote: Would you know why this is using hundreds of mb of rams? Hi, What type is CircleShape? If it is a class, or otherwise contains pointers, then this is probably the source of your problem. You are storing high-entropy data (floating-poi

Re: Print to Win Printer

2015-01-27 Thread Vladimir Panteleev via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 21:32:34 UTC, Paul wrote: How do I print to a Windows printer from a console program? Thanks for your assistance. You can save your document to a temporary file, then call ShellExecute with a path to the file and the "print" command.

why there is no TBase in thrift for dlang?

2015-01-27 Thread zhmt via Digitalmars-d-learn
I am writing code below: private Cmd deserialCmd(ubyte[] data) { Cmd ret; TMemoryBuffer trans = new TMemoryBuffer(data); auto prot = new TCompactProtocol!TMemoryBuffer(trans); ret.read(prot); return ret;

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread FG via Digitalmars-d-learn
On 2015-01-28 at 03:04, Vladimir Panteleev wrote: What type is CircleShape? If it is a class, or otherwise contains pointers, then this is probably the source of your problem. class CircleShape : Shape is defined in dsfml.graphics.circleshape, so there's no going around this... - Building y

Re: vibe.d error

2015-01-27 Thread David Monagle via Digitalmars-d-learn
What version of dub are you using?

Re: why there is no TBase in thrift for dlang?

2015-01-27 Thread zhmt via Digitalmars-d-learn
I resovled it by Generic programming : private const (ubyte)[] serialObj(T) (T obj) { TMemoryBuffer trans = new TMemoryBuffer(); auto prot = new TCompactProtocol!TMemoryBuffer(trans); obj.write(prot); return trans.get

Re: why there is no TBase in thrift for dlang?

2015-01-27 Thread zhmt via Digitalmars-d-learn
sorry , I am quite new to dlang.

Re: vibe.d error

2015-01-27 Thread Suliman via Digitalmars-d-learn
Try to update dub. There was issue in old version with path with whitespace.

Re: I left my program open for 9 hours and it used up 700mb of ram, could someone review it?

2015-01-27 Thread Gan via Digitalmars-d-learn
On Wednesday, 28 January 2015 at 02:50:11 UTC, FG wrote: On 2015-01-28 at 03:04, Vladimir Panteleev wrote: What type is CircleShape? If it is a class, or otherwise contains pointers, then this is probably the source of your problem. class CircleShape : Shape is defined in dsfml.graphics.circ

Re: vibe.d error

2015-01-27 Thread Phil via Digitalmars-d-learn
I was using 0.9.21. Upgrading has fixed this issue, thanks to you both.