Re: Using phobos as shared library for multiple binaries

2015-12-05 Thread tcak via Digitalmars-d-learn
On Saturday, 5 December 2015 at 21:49:52 UTC, Ralf wrote: Hi, I've written several small command-line utilities in D that are to be shipped together in one package. Each one of them only would be only a few kB in size, but they end up being ~1Mb, I assume because every one links statically

Re: static array crashes my program

2015-12-05 Thread John Colvin via Digitalmars-d-learn
On Saturday, 5 December 2015 at 09:49:06 UTC, ref2401 wrote: I want to create a static array large enough to store 1MB of float values. What am I doing wrong? Here is a sample code with notes: void main(string[] args) { enum size_t COUNT = 1024 * 512 / float.sizeof; // works OK :)

Re: static array crashes my program

2015-12-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/5/15 8:09 AM, John Colvin wrote: On Saturday, 5 December 2015 at 09:49:06 UTC, ref2401 wrote: I want to create a static array large enough to store 1MB of float values. What am I doing wrong? Here is a sample code with notes: void main(string[] args) { enum size_t COUNT = 1024 * 512

Re: Reset all Members of a Aggregate Instance

2015-12-05 Thread Ali Çehreli via Digitalmars-d-learn
On 12/05/2015 01:32 AM, Observer wrote: Won't clear(c); do the trick? ((pp187-188 of TDPL) clear() has been renamed as destroy() but it won't work by itself because the OP wants a reusable object. I think, in addition to destroy(), the default constructor should be run:

Re: Reset all Members of a Aggregate Instance

2015-12-05 Thread Chris Wright via Digitalmars-d-learn
On Sat, 05 Dec 2015 07:48:16 -0800, Ali Çehreli wrote: > On 12/05/2015 01:32 AM, Observer wrote: > >> Won't clear(c); do the trick? ((pp187-188 of TDPL) > > clear() has been renamed as destroy() but it won't work by itself > because the OP wants a reusable object. I think, in addition to >

Re: Reset all Members of a Aggregate Instance

2015-12-05 Thread Jakob Ovrum via Digitalmars-d-learn
On Saturday, 5 December 2015 at 16:28:18 UTC, Chris Wright wrote: The default constructor doesn't set default field values, though, which is why my solution involved copying ClassInfo.init. Thanks, this is a handy factoid. Reminds me of the whole __dtor vs __xdtor debacle.

Re: benchmark on binary trees

2015-12-05 Thread JR via Digitalmars-d-learn
On Friday, 4 December 2015 at 14:06:26 UTC, Alex wrote: [...] hoping it would be faster. This was not the case. Why? [...] Is there anything else to improve performance significantly? Profile. Profile profile profile. Callgrind. Find bottlenecks instead of guessing them.

Re: Using phobos as shared library for multiple binaries

2015-12-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 5 December 2015 at 21:49:52 UTC, Ralf wrote: I've written several small command-line utilities in D that are to be shipped together in one package. I'm not sure if shared lib support is on Mac or not (I know it is on Linux but mac is different...). But do they need to actually

using parse with string slice

2015-12-05 Thread Quentin Ladeveze via Digitalmars-d-learn
Hi, I try to parse some hexadecimal numbers stocked in a string. So I use this code --- import std.conv; string s = "B"; int value = parse!int(s, 16); assert(value == 11); --- But when I have several hexadecimal numbers in the string, and I slice it, the compiler can't deduce which

Re: using parse with string slice

2015-12-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 5 December 2015 at 22:05:11 UTC, anonymous wrote: You can use std.conv.to instead or assign the slice to a variable first. This is a bit of a FAQ I think because people don't realize you can use to and parse to do the same thing. The big difference is parse will advance the

Do a class invariants affect -release builds?

2015-12-05 Thread Andrew LaChance via Digitalmars-d-learn
I was reading a blog post here: http://3d.benjamin-thaut.de/?p=20 which mentions: "Calls to the druntime invariant handler are emitted in release build also and there is no way to turn them off. Even if the class does not have any invariants the invariant handler will always be called, walk

Re: Do a class invariants affect -release builds?

2015-12-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/5/15 6:06 PM, Andrew LaChance wrote: I was reading a blog post here: http://3d.benjamin-thaut.de/?p=20 which mentions: "Calls to the druntime invariant handler are emitted in release build also and there is no way to turn them off. Even if the class does not have any invariants the

Re: Do a class invariants affect -release builds?

2015-12-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/5/15 6:54 PM, Chris Wright wrote: I've never used a release build of anything. Bounds checking isn't that expensive. void main() { int[] arr = new int[10]; assert(arr.capacity == 1000); // obviously wrong arr[10] = 5; } dmd -release -boundscheck=on testboundscheck.d

Re: Do a class invariants affect -release builds?

2015-12-05 Thread Chris Wright via Digitalmars-d-learn
On Sat, 05 Dec 2015 23:06:22 +, Andrew LaChance wrote: > I was reading a blog post here: http://3d.benjamin-thaut.de/?p=20 which > mentions: > > "Calls to the druntime invariant handler are emitted in release build > also and there is no way to turn them off. Even if the class does not >

Re: Reset all Members of a Aggregate Instance

2015-12-05 Thread Observer via Digitalmars-d-learn
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote: Given class C { // lots of members } and a function f(C c) { } is there a generic way, perhaps through reflection, to reset (inside f) all members of `c` to their default values? Something along

static array crashes my program

2015-12-05 Thread ref2401 via Digitalmars-d-learn
I want to create a static array large enough to store 1MB of float values. What am I doing wrong? Here is a sample code with notes: void main(string[] args) { enum size_t COUNT = 1024 * 512 / float.sizeof; // works OK :) //enum size_t COUNT = 1024 * 512 * 2 / float.sizeof; //

Re: static array crashes my program

2015-12-05 Thread Olivier Pisano via Digitalmars-d-learn
On Saturday, 5 December 2015 at 09:49:06 UTC, ref2401 wrote: I want to create a static array large enough to store 1MB of float values. What am I doing wrong? Here is a sample code with notes: void main(string[] args) { enum size_t COUNT = 1024 * 512 / float.sizeof; // works OK :)

Re: benchmark on binary trees

2015-12-05 Thread anonymous via Digitalmars-d-learn
On 05.12.2015 01:40, Alex wrote: found and tried out the -vgc option... Is there a way to deactivate the GC, if it stands in way? You can call core.memory.GC.disable to disable automatic collections. .enable to turn them on again. http://dlang.org/phobos/core_memory.html#.GC Yes, I

Using phobos as shared library for multiple binaries

2015-12-05 Thread Ralf via Digitalmars-d-learn
Hi, I've written several small command-line utilities in D that are to be shipped together in one package. Each one of them only would be only a few kB in size, but they end up being ~1Mb, I assume because every one links statically parts of the standard library. How can this be improved?

Re: using parse with string slice

2015-12-05 Thread Quentin Ladeveze via Digitalmars-d-learn
On Saturday, 5 December 2015 at 22:05:11 UTC, anonymous wrote: On 05.12.2015 22:59, Quentin Ladeveze wrote: --- import std.conv; string s = "1B2A"; int value = parse!int(s[0..2], 16); //template std.conv.parse cannot deduce function from argument types !(int)(string, int) --- Does someone

Re: using parse with string slice

2015-12-05 Thread anonymous via Digitalmars-d-learn
On 05.12.2015 22:59, Quentin Ladeveze wrote: --- import std.conv; string s = "1B2A"; int value = parse!int(s[0..2], 16); //template std.conv.parse cannot deduce function from argument types !(int)(string, int) --- Does someone have an idea of why it happens ? The version of parse that is used