Quick int pointer allocation question

2012-09-14 Thread monarch_dodra
This is going to be quick: Is it possible to allocate and initialize an int in the same line? int* p = new int(5); I haven't found a way to 1 liner it. Is it possible? Do I have to two liner it? int* p = new int(); *p = 5; Thanks.

Re: Quick int pointer allocation question

2012-09-14 Thread monarch_dodra
On Friday, 14 September 2012 at 09:20:03 UTC, monarch_dodra wrote: This is going to be quick: Is it possible to allocate and initialize an int in the same line? int* p = new int(5); I haven't found a way to 1 liner it. Is it possible? Do I have to two liner it? int* p = new int(); *p = 5;

Re: Quick int pointer allocation question

2012-09-14 Thread David
Whilst I'm on the subject of questions, how does one allocate, but bypassing the extra memcpy of T.init? Is this possible? int x = void; http://dpaste.dzfl.pl/24c1baa9

Re: Quick int pointer allocation question

2012-09-14 Thread Jonathan M Davis
On Friday, September 14, 2012 11:20:16 monarch_dodra wrote: This is going to be quick: Is it possible to allocate and initialize an int in the same line? int* p = new int(5); I haven't found a way to 1 liner it. Is it possible? Nope. Though I think that it should be. Do I have to two

Re: Quick int pointer allocation question

2012-09-14 Thread monarch_dodra
On Friday, 14 September 2012 at 10:33:47 UTC, David wrote: Whilst I'm on the subject of questions, how does one allocate, but bypassing the extra memcpy of T.init? Is this possible? int x = void; http://dpaste.dzfl.pl/24c1baa9 Hum, but that is a stack allocated variable. What about:

Re: Quick int pointer allocation question

2012-09-14 Thread Jacob Carlborg
On 2012-09-14 12:52, monarch_dodra wrote: int x = void; http://dpaste.dzfl.pl/24c1baa9 Hum, but that is a stack allocated variable. Perhaps using GC.malloc? -- /Jacob Carlborg

Re: Quick int pointer allocation question

2012-09-14 Thread monarch_dodra
On Friday, 14 September 2012 at 11:17:55 UTC, Jacob Carlborg wrote: On 2012-09-14 12:52, monarch_dodra wrote: int x = void; http://dpaste.dzfl.pl/24c1baa9 Hum, but that is a stack allocated variable. Perhaps using GC.malloc? Hum, apparently, there is a second (default aka-hidden)

Re: Quick int pointer allocation question

2012-09-14 Thread Steven Schveighoffer
On Fri, 14 Sep 2012 05:20:16 -0400, monarch_dodra monarchdo...@gmail.com wrote: This is going to be quick: Is it possible to allocate and initialize an int in the same line? int* p = new int(5); I haven't found a way to 1 liner it. Is it possible? Do I have to two liner it? int* p = new

Re: Quick int pointer allocation question

2012-09-14 Thread monarch_dodra
On Friday, 14 September 2012 at 14:33:51 UTC, Steven Schveighoffer wrote: On Fri, 14 Sep 2012 05:20:16 -0400, monarch_dodra monarchdo...@gmail.com wrote: This is going to be quick: Is it possible to allocate and initialize an int in the same line? int* p = new int(5); I haven't found a way

Re: Quick int pointer allocation question

2012-09-14 Thread bearophile
monarch_dodra: int *p = [5].ptr; -Steve But see this benchmark: void main() { auto pointers = new int*[1_000_000]; foreach (int i, ref p; pointers) p = [i].ptr; foreach (i; 0U .. 4_000_000_000U) {} } On my 32 bit system its RAM commit is about 23 MB. The pointers

Re: Quick int pointer allocation question

2012-09-14 Thread Simen Kjaeraas
On Fri, 14 Sep 2012 16:27:55 +0200, monarch_dodra monarchdo...@gmail.com wrote: On Friday, 14 September 2012 at 11:17:55 UTC, Jacob Carlborg wrote: On 2012-09-14 12:52, monarch_dodra wrote: int x = void; http://dpaste.dzfl.pl/24c1baa9 Hum, but that is a stack allocated variable.

Task management

2012-09-14 Thread Martin Drasar
Hi, can anyone tell me what is the good (for arbitrary low values of good) way to forcibly end a running task? I am using a task pool from std.parallelism to execute delegates supplied by various plugins. As I have no real control over what gets executed and how, there is always a possibility

Re: Quick int pointer allocation question

2012-09-14 Thread Maxim Fomin
On Friday, 14 September 2012 at 09:20:03 UTC, monarch_dodra wrote: This is going to be quick: Is it possible to allocate and initialize an int in the same line? int* p = new int(5); I haven't found a way to 1 liner it. Is it possible? Do I have to two liner it? int* p = new int(); *p = 5;

Re: Quick int pointer allocation question

2012-09-14 Thread bearophile
monarch_dodra: I'm allocating an array of 500_000 ulongs, and afterwards, I'm initializing them all by hand, making the default allocation useless. In std.array there are two functions to avoid a double initialization, mostly to be used for nonreference data. Bye, bearophile

Re: Quick int pointer allocation question

2012-09-14 Thread Chris Cain
On Friday, 14 September 2012 at 18:14:54 UTC, bearophile wrote: monarch_dodra: I'm allocating an array of 500_000 ulongs, and afterwards, I'm initializing them all by hand, making the default allocation useless. In std.array there are two functions to avoid a double initialization, mostly

Quick question about new semantics

2012-09-14 Thread monarch_dodra
I have a struct, which defines a constructor that takes an argument. Now, I'd like to new this object, to it's default T.init value (eg call new, but now constructors): struct S { this(int); } void main() { auto p1 = new S; auto p2 = new S(); } main.d(8):

Re: Quick int pointer allocation question

2012-09-14 Thread monarch_dodra
On Friday, 14 September 2012 at 14:27:43 UTC, monarch_dodra wrote: On Friday, 14 September 2012 at 11:17:55 UTC, Jacob Carlborg wrote: Perhaps using GC.malloc? Hum, apparently, there is a second (default aka-hidden) argument that is a bitmask applied to the allocated memory. So not much

Re: Quick int pointer allocation question

2012-09-14 Thread Steven Schveighoffer
On Fri, 14 Sep 2012 13:03:37 -0400, bearophile bearophileh...@lycos.com wrote: monarch_dodra: int *p = [5].ptr; -Steve But see this benchmark: void main() { auto pointers = new int*[1_000_000]; foreach (int i, ref p; pointers) p = [i].ptr; foreach (i; 0U ..

Re: Quick question about new semantics

2012-09-14 Thread Steven Schveighoffer
On Fri, 14 Sep 2012 14:27:56 -0400, monarch_dodra monarchdo...@gmail.com wrote: I have a struct, which defines a constructor that takes an argument. Now, I'd like to new this object, to it's default T.init value (eg call new, but now constructors): struct S { this(int); }

Re: Quick int pointer allocation question

2012-09-14 Thread bearophile
Steven Schveighoffer: it has to do with the fact that the minimum heap block is 16-bytes (or 4 ints wide). Extra 3 bytes is probably for overhead and static data. If instead of p = [i].ptr; you did p = new int; *p = i; You would get the same exact behavior. No way around this, unless you

Re: Quick int pointer allocation question

2012-09-14 Thread Steven Schveighoffer
On Fri, 14 Sep 2012 15:23:40 -0400, monarch_dodra monarchdo...@gmail.com wrote: Anybody know what the attribute FINALIZE (Finalize the data in this block on collect) means? Don't use it. It specifies that the block is a D class instance, and so has a vtable with a finalizer referenced

Re: Quick question about new semantics

2012-09-14 Thread Jonathan M Davis
On Friday, September 14, 2012 20:27:56 monarch_dodra wrote: I have a struct, which defines a constructor that takes an argument. Now, I'd like to new this object, to it's default T.init value (eg call new, but now constructors): struct S { this(int); } void main() { auto