Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread ketmar via Digitalmars-d-learn
On Sat, 14 Feb 2015 00:57:33 +, weaselcat wrote: > On Friday, 13 February 2015 at 22:55:27 UTC, anonymous wrote: >> On Thursday, 12 February 2015 at 23:52:41 UTC, Foo wrote: >>> This is something I've done recently. >>> Would be glad if my code will help you: https://github.com/Dgame/m3 >>> Es

Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread ketmar via Digitalmars-d-learn
On Fri, 13 Feb 2015 23:29:10 +, Foo wrote: > Always the same in this newsgroup. You want to help as good as you can > (even if it's not perfect) and all you get are subliminal messages... :) code that you throwing at newcomer may not be perfect, but it at least should not be wrong. your code

shallowCopyFrom: how to shallow copy objects / swap contents ?

2015-02-13 Thread Timothee Cour via Digitalmars-d-learn
Is there a standard way to shallow copy objects? eg: class A{ int* a; string b; } unittest{ auto a=new A; a.a=new int(1); a.b="asdf"; auto b=new A; b.shallowCopyFrom(a); assert(b.a==a.a); assert(b.b==a.b); } How about: option A1: void shallowCopyFrom(T)(T a, T b) if(is(T==cla

Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread weaselcat via Digitalmars-d-learn
On Friday, 13 February 2015 at 22:55:27 UTC, anonymous wrote: On Thursday, 12 February 2015 at 23:52:41 UTC, Foo wrote: This is something I've done recently. Would be glad if my code will help you: https://github.com/Dgame/m3 Especially the m3.d module could be useful for you. /* Class and Str

Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread bearophile via Digitalmars-d-learn
Foo: I'm regret that I tried to help, I will delete this repo as far as possible. :) Language communities aren't perfect, but the success of a language comes from the help of many little hands :) Perhaps Rust will "win" over D in the end, but there's no reason to throw away your work just f

Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread Kitt via Digitalmars-d-learn
On Friday, 13 February 2015 at 23:29:11 UTC, Foo wrote: On Friday, 13 February 2015 at 23:13:05 UTC, anonymous wrote: On Friday, 13 February 2015 at 23:04:25 UTC, Foo wrote: Don't understand me wrong. My code is not perfect, but maybe it can be helpful for someone. As it is right now, I fear

Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread Foo via Digitalmars-d-learn
On Friday, 13 February 2015 at 23:13:05 UTC, anonymous wrote: On Friday, 13 February 2015 at 23:04:25 UTC, Foo wrote: Don't understand me wrong. My code is not perfect, but maybe it can be helpful for someone. As it is right now, I fear it may do more harm than good. Always the same in this

Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread anonymous via Digitalmars-d-learn
On Friday, 13 February 2015 at 23:04:25 UTC, Foo wrote: Don't understand me wrong. My code is not perfect, but maybe it can be helpful for someone. As it is right now, I fear it may do more harm than good.

Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread Foo via Digitalmars-d-learn
On Friday, 13 February 2015 at 22:55:27 UTC, anonymous wrote: On Thursday, 12 February 2015 at 23:52:41 UTC, Foo wrote: This is something I've done recently. Would be glad if my code will help you: https://github.com/Dgame/m3 Especially the m3.d module could be useful for you. /* Class and Str

Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread anonymous via Digitalmars-d-learn
On Thursday, 12 February 2015 at 23:52:41 UTC, Foo wrote: This is something I've done recently. Would be glad if my code will help you: https://github.com/Dgame/m3 Especially the m3.d module could be useful for you. /* Class and Struct */ emplace: You can't assume zero-initialization for struc

Re: Number of Bits Needed to Represent a Zero-Offset Integer

2015-02-13 Thread bearophile via Digitalmars-d-learn
H. S. Teoh: So it could be called ilog2? Perhaps floorIlog2? Isn't ilog2 a different function? Bye, bearophile

Re: Number of Bits Needed to Represent a Zero-Offset Integer

2015-02-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 13, 2015 at 07:54:32PM +, via Digitalmars-d-learn wrote: > On Friday, 13 February 2015 at 15:14:44 UTC, H. S. Teoh wrote: > >Isn't it essentially floor(log_2(a)), mathematically speaking? Maybe > >that could be the basis of a better name? > > integer log2: > https://graphics.stanfo

Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread Kitt via Digitalmars-d-learn
On Friday, 13 February 2015 at 05:56:37 UTC, Jakob Ovrum wrote: This issue, ... [is] related to the loss of guarantee attributes when using TypeInfo methods, most recently discussed in this thread[1]. It is essentially a bug, and a work in progress. I see. So, in theory, after some patching e

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/15 4:08 PM, "Marc =?UTF-8?B?U2Now7x0eiI=?= " wrote: On Friday, 13 February 2015 at 19:09:43 UTC, Tobias Pankrath wrote: 1. Throw preallocated exceptions is the way to go and because noone has yet shown an explicit example: void myThrowingNogcFunc() @nogc { static co

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread via Digitalmars-d-learn
On Friday, 13 February 2015 at 19:09:43 UTC, Tobias Pankrath wrote: 1. Throw preallocated exceptions is the way to go ... and because noone has yet shown an explicit example: void myThrowingNogcFunc() @nogc { static const exc = new Exception("something went wrong"); throw e

Re: Number of Bits Needed to Represent a Zero-Offset Integer

2015-02-13 Thread via Digitalmars-d-learn
On Friday, 13 February 2015 at 15:14:44 UTC, H. S. Teoh wrote: Isn't it essentially floor(log_2(a)), mathematically speaking? Maybe that could be the basis of a better name? integer log2: https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogFloat

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread Jonathan Marler via Digitalmars-d-learn
On Friday, 13 February 2015 at 19:10:00 UTC, Adam D. Ruppe wrote: On Friday, 13 February 2015 at 19:03:10 UTC, Jonathan Marler wrote: T construct(T,A...)(void* buffer, A args) { return (cast(T)buffer).__ctor(args); } This is wrong, you need to initialize the memory first to the proper values

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread Jonathan Marler via Digitalmars-d-learn
On Friday, 13 February 2015 at 19:13:02 UTC, Steven Schveighoffer wrote: You need to actually allocate the memory on the heap. Your data lives on the stack frame of main, which goes away as soon as main exits, and your exception is caught outside main. -Steve Yes I am aware of this. That do

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/15 2:03 PM, Jonathan Marler wrote: This question comes from wanting to be able to throw an exception in code that is @nogc. I don't know if it's possible but I'd like to be able to throw an exception without allocating memory for the garbage collector? You can do it in C++ so I think you

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 13 February 2015 at 19:03:10 UTC, Jonathan Marler wrote: T construct(T,A...)(void* buffer, A args) { return (cast(T)buffer).__ctor(args); } This is wrong, you need to initialize the memory first to the proper values for the class, gotten via typeid(T).init. std.conv.emplace does

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread Tobias Pankrath via Digitalmars-d-learn
On Friday, 13 February 2015 at 19:03:10 UTC, Jonathan Marler wrote: This question comes from wanting to be able to throw an exception in code that is @nogc. I don't know if it's possible but I'd like to be able to throw an exception without allocating memory for the garbage collector? You ca

I can has @nogc and throw Exceptions?

2015-02-13 Thread Jonathan Marler via Digitalmars-d-learn
This question comes from wanting to be able to throw an exception in code that is @nogc. I don't know if it's possible but I'd like to be able to throw an exception without allocating memory for the garbage collector? You can do it in C++ so I think you should be able to in D. One idea I ha

Re: Derelict OpenGL basic program does not work but OpenGL does not say anything is wrong?

2015-02-13 Thread Bennet via Digitalmars-d-learn
On Friday, 13 February 2015 at 09:18:29 UTC, Mike Parker wrote: On 2/13/2015 6:14 PM, Mike Parker wrote: On 2/13/2015 12:46 PM, Bennet wrote: I've begun writing some basic OpenGL code using DerelictGL3 but I've hit a wall. I've managed to open a window (with DerelictSDL2) and call basic OpenGL

Re: dmd-2.067.0-b1

2015-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/15 9:01 AM, anonymous wrote: On Friday, 13 February 2015 at 13:25:55 UTC, Steven Schveighoffer wrote: Yes, the operator precedence (curiously not defined in the spec) is here: http://wiki.dlang.org/Operator_precedence Conditional operator is above assignment operators. It's specified

Re: Number of Bits Needed to Represent a Zero-Offset Integer

2015-02-13 Thread bearophile via Digitalmars-d-learn
H. S. Teoh: Maybe that could be the basis of a better name? Right. Bye, bearophile

Re: Number of Bits Needed to Represent a Zero-Offset Integer

2015-02-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 13, 2015 at 12:28:23PM +, bearophile via Digitalmars-d-learn wrote: > Dominikus Dittes Scherkl: > > >I would recommend to use something like this: > > > >/// returns the number of the highest set bit +1 in the given value > >/// or 0 if no bit is set > >size_t bitlen(T)(const(T) a

Re: dmd-2.067.0-b1

2015-02-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 13 February 2015 at 13:25:55 UTC, Steven Schveighoffer wrote: On 2/13/15 7:38 AM, tcak wrote: On Friday, 13 February 2015 at 09:38:04 UTC, Dennis Ritchie wrote: This is a bug? import std.stdio; void main() { int a = 0; writeln( (a < 10) ? a = 1 : a = 2 );// prints 2

Re: dmd-2.067.0-b1

2015-02-13 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 13 February 2015 at 09:38:04 UTC, Dennis Ritchie wrote: This is a bug? import std.stdio; void main() { int a = 0; writeln( (a < 10) ? a = 1 : a = 2 );// prints 2 writeln( (a < 10) ? a = 1 : (a = 2) ); // prints 1 } Even C++ output: 1 1 Maybe a similar issue as t

Re: dmd-2.067.0-b1

2015-02-13 Thread anonymous via Digitalmars-d-learn
On Friday, 13 February 2015 at 13:25:55 UTC, Steven Schveighoffer wrote: Yes, the operator precedence (curiously not defined in the spec) is here: http://wiki.dlang.org/Operator_precedence Conditional operator is above assignment operators. It's specified through the grammar [1]: Assig

Re: dmd-2.067.0-b1

2015-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/15 7:38 AM, tcak wrote: On Friday, 13 February 2015 at 09:38:04 UTC, Dennis Ritchie wrote: This is a bug? import std.stdio; void main() { int a = 0; writeln( (a < 10) ? a = 1 : a = 2 );// prints 2 writeln( (a < 10) ? a = 1 : (a = 2) ); // prints 1 } Even C++ output:

Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread via Digitalmars-d-learn
On Friday, 13 February 2015 at 13:07:04 UTC, bearophile wrote: I suggest you to read how a mark&sweep GC works, or better to implement a bare-bones mark&sweep GC in C language yourself for Lisp-like cons cells, you only need 100 lines of code or so to do it. Got it. Thanks.

Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread bearophile via Digitalmars-d-learn
Per Nordlöw: Then how does the GC know when to release when there are multiple references? The mark phase counts what's reachable and what can't be reached. If an object has one pointer to it, or one hundred pointers, it is not removed. If nothing points to it, it is removed. I suggest you

Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread Tobias Pankrath via Digitalmars-d-learn
On Friday, 13 February 2015 at 12:58:40 UTC, Per Nordlöw wrote: On Friday, 13 February 2015 at 12:50:14 UTC, Tobias Pankrath wrote: There are no reference counts involved, just simple arithmetic. string a = "abc"; string b = a[1 .. $]; Then how does the GC know when to release when there are

Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread via Digitalmars-d-learn
On Friday, 13 February 2015 at 12:50:14 UTC, Tobias Pankrath wrote: There are no reference counts involved, just simple arithmetic. string a = "abc"; string b = a[1 .. $]; Then how does the GC know when to release when there are multiple references? Is this because string references immutab

Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread Tobias Pankrath via Digitalmars-d-learn
On Friday, 13 February 2015 at 12:40:57 UTC, Per Nordlöw wrote: On Friday, 13 February 2015 at 11:52:50 UTC, Tobias Pankrath wrote: On Friday, 13 February 2015 at 11:34:50 UTC, Per Nordlöw wrote: On Friday, 13 February 2015 at 09:13:48 UTC, Kagamin wrote: Whether s.front uses GC is determined b

Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread via Digitalmars-d-learn
On Friday, 13 February 2015 at 11:52:50 UTC, Tobias Pankrath wrote: On Friday, 13 February 2015 at 11:34:50 UTC, Per Nordlöw wrote: On Friday, 13 February 2015 at 09:13:48 UTC, Kagamin wrote: Whether s.front uses GC is determined by s.front implementation, caller can't affect it. Compiling h

Re: dmd-2.067.0-b1

2015-02-13 Thread tcak via Digitalmars-d-learn
On Friday, 13 February 2015 at 09:38:04 UTC, Dennis Ritchie wrote: This is a bug? import std.stdio; void main() { int a = 0; writeln( (a < 10) ? a = 1 : a = 2 );// prints 2 writeln( (a < 10) ? a = 1 : (a = 2) ); // prints 1 } Even C++ output: 1 1 About 2 years ago, I had a

Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread bearophile via Digitalmars-d-learn
Tobias Pankrath: Why should splitter.front allocate? I think that front was able to throw Unicode exceptions, that require the GC. But I think later they have become asserts, that don't require the GC. Bye, bearophile

Re: Number of Bits Needed to Represent a Zero-Offset Integer

2015-02-13 Thread bearophile via Digitalmars-d-learn
Dominikus Dittes Scherkl: I would recommend to use something like this: /// returns the number of the highest set bit +1 in the given value or 0 if no bit is set size_t bitlen(T)(const(T) a) pure @safe @nogc nothrow if(isUnsigned!T) { static if(T.sizeof <= size_t.sizeof) // doesn't work f

Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread Tobias Pankrath via Digitalmars-d-learn
On Friday, 13 February 2015 at 11:34:50 UTC, Per Nordlöw wrote: On Friday, 13 February 2015 at 09:13:48 UTC, Kagamin wrote: Whether s.front uses GC is determined by s.front implementation, caller can't affect it. Compiling https://github.com/nordlow/justd/blob/master/t_splitter.d with -vgc o

Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread via Digitalmars-d-learn
On Friday, 13 February 2015 at 09:13:48 UTC, Kagamin wrote: Whether s.front uses GC is determined by s.front implementation, caller can't affect it. Compiling https://github.com/nordlow/justd/blob/master/t_splitter.d with -vgc on dmd git master gives no warnings about GC allocations! Is th

Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread Tobias Pankrath via Digitalmars-d-learn
On Friday, 13 February 2015 at 08:21:53 UTC, Per Nordlöw wrote: When reading/parsing data from disk often try to write code such as foreach (const line; File(filePath).byLine) { auto s = line.splitter(" ") const x = s.front.to!uint; s.popFront; const y = s.front

Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread via Digitalmars-d-learn
On Friday, 13 February 2015 at 09:13:48 UTC, Kagamin wrote: Whether s.front uses GC is determined by s.front implementation, caller can't affect it. I'm talking about internal changes to DMD, in this case.

Re: GC has a "barbaric" destroyng model, I think

2015-02-13 Thread Kagamin via Digitalmars-d-learn
Yeah, since @trusted is checked manually, it's sort of a problem, if you don't know, how to check it.

Re: GC has a "barbaric" destroyng model, I think

2015-02-13 Thread Foo via Digitalmars-d-learn
On Friday, 13 February 2015 at 09:28:30 UTC, Kagamin wrote: On Friday, 13 February 2015 at 09:11:26 UTC, Foo wrote: And I wouldn't say indiscriminately. Every function I marked with @trusted was checked by me so far. What did you check them for? :) Just first example: make and destruct, being

dmd-2.067.0-b1

2015-02-13 Thread Dennis Ritchie via Digitalmars-d-learn
This is a bug? import std.stdio; void main() { int a = 0; writeln( (a < 10) ? a = 1 : a = 2 );// prints 2 writeln( (a < 10) ? a = 1 : (a = 2) ); // prints 1 } Even C++ output: 1 1

Re: GC has a "barbaric" destroyng model, I think

2015-02-13 Thread Kagamin via Digitalmars-d-learn
On Friday, 13 February 2015 at 09:11:26 UTC, Foo wrote: And I wouldn't say indiscriminately. Every function I marked with @trusted was checked by me so far. What did you check them for? :) Just first example: make and destruct, being marked as @trusted, don't prevent caller from UAF and double

Re: Derelict OpenGL basic program does not work but OpenGL does not say anything is wrong?

2015-02-13 Thread Mike Parker via Digitalmars-d-learn
On 2/13/2015 6:14 PM, Mike Parker wrote: On 2/13/2015 12:46 PM, Bennet wrote: I've begun writing some basic OpenGL code using DerelictGL3 but I've hit a wall. I've managed to open a window (with DerelictSDL2) and call basic OpenGL functions such as glClear(). Still I can not get a basic triangle

Re: GC has a "barbaric" destroyng model, I think

2015-02-13 Thread Foo via Digitalmars-d-learn
On Friday, 13 February 2015 at 08:00:43 UTC, Kagamin wrote: On Thursday, 12 February 2015 at 17:29:34 UTC, Foo wrote: And since today it is @safe wherever possible. Well, you marked functions @trusted rather indiscriminately :) Such approach doesn't really improve safety, and the code could w

Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread Kagamin via Digitalmars-d-learn
Whether s.front uses GC is determined by s.front implementation, caller can't affect it.

Re: Derelict OpenGL basic program does not work but OpenGL does not say anything is wrong?

2015-02-13 Thread Mike Parker via Digitalmars-d-learn
On 2/13/2015 12:46 PM, Bennet wrote: I've begun writing some basic OpenGL code using DerelictGL3 but I've hit a wall. I've managed to open a window (with DerelictSDL2) and call basic OpenGL functions such as glClear(). Still I can not get a basic triangle up and running. glError() does not return

Re: Number of Bits Needed to Represent a Zero-Offset Integer

2015-02-13 Thread via Digitalmars-d-learn
On Monday, 19 January 2015 at 20:54:50 UTC, Steven Schveighoffer wrote: Cool. I would point out that the commented code suggests you should be handling the 0 case, but you are not (when T.min == T.max) Should I do a Phobos PR for this? If so where should I put it?

Data-Flow (Escape) Analysis to Aid in Avoiding GC

2015-02-13 Thread via Digitalmars-d-learn
When reading/parsing data from disk often try to write code such as foreach (const line; File(filePath).byLine) { auto s = line.splitter(" ") const x = s.front.to!uint; s.popFront; const y = s.front.to!double; s.popFront; ... } In response to all the

Re: Derelict OpenGL basic program does not work but OpenGL does not say anything is wrong?

2015-02-13 Thread Nils Forsman via Digitalmars-d-learn
void main(){ DerelictGL3.load(); //create your sdl context, window hints, DerelictGL3.reload(); //Do other stuff... } You got to have a valid context before you call reload. These two functions shall be called only once, I have the impression that you call them multiple times.

Re: GC has a "barbaric" destroyng model, I think

2015-02-13 Thread Kagamin via Digitalmars-d-learn
On Thursday, 12 February 2015 at 17:29:34 UTC, Foo wrote: And since today it is @safe wherever possible. Well, you marked functions @trusted rather indiscriminately :) Such approach doesn't really improve safety, and the code could work as well being @system. It's not like @system is inherentl