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.
V Tue, 27 Jan 2015 04:38:57 +
David Monagle via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com 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
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}; //static used
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,
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
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
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.
Ali
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 ==
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
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
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
Oope, yeah, and it ran.
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? ;-)
signature.asc
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
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
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
And it's named dynamic array, instead of Array List object,
it's not a class instance.
Bye,
bearophile
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 =
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
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
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(){
auto a =
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 that
How do I print to a Windows printer from a console program?
Thanks for your assistance.
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;
etc.
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(){
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
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
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
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 name vibe.d
cd name
dub
Results in
Fetching libevent 2.0.1+2.0.16...
Error executing command upgrade: Failed to download
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 struct is not a
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 what you 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.
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)
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
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
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
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.
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
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
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
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
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
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
Baz:
doesn't work. And similarly to the the orginal post:
I suggest to read some D documentation first, and program later.
Bye,
bearophile
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.
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 ==
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
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?
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
-
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)
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
I was using 0.9.21. Upgrading has fixed this issue, thanks to you
both.
sorry , I am quite new to dlang.
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
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
Try to update dub. There was issue in old version with path with
whitespace.
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 implementation.
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
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
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
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)
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,
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?
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;
63 matches
Mail list logo