Void initialization

2011-12-19 Thread Bear
Using D1, I have a program that creates tons of float[] ; for performance reasons, I would like them to be uninitialized. I've tried replacing float[] f = new float[x]; by float[] f = cast(float[])std.gc.malloc(x*4); Unfortunately I keep running into Access violation and sometimes Array bounds

Re: Void initialization

2011-12-19 Thread Trass3r
Am 19.12.2011, 13:04 Uhr, schrieb Bear joanylepri...@yahoo.fr: Using D1, I have a program that creates tons of float[] ; for performance reasons, I would like them to be uninitialized. std.array.uninitializedArray

Re: delegate, template and alias

2011-12-19 Thread Heromyth
== Quote from Philippe Sigaud (philippe.sig...@gmail.com)'s article On Sun, Dec 18, 2011 at 14:13, Heromyth bitwo...@qq.com wrote: I have a delegate as a parameter in a function which is a template function. And I want to use alias for the delegate parameter. Is there a better way for this?

Re: delegate, template and alias

2011-12-19 Thread Heromyth
== Quote from Heromyth (bitwo...@qq.com)'s article == Quote from Philippe Sigaud (philippe.sig...@gmail.com)'s article I suppose you do *not*want the commented line? I want to convert a delegate type define in C# to D's, as such: public delegate void AsynchronousActionT(T argument,

Re: Array expanding

2011-12-19 Thread Steven Schveighoffer
On Sun, 18 Dec 2011 18:42:31 -0500, Jonathan M Davis jmdavisp...@gmx.com wrote: On Sunday, December 18, 2011 22:12:07 RenatoL wrote: Reading the book from Alexandrescu we can find this (page 103-104, at least in my edition): Expanding arrays has a couple of subtleties that concern possible

Re: Void initialization

2011-12-19 Thread Steven Schveighoffer
On Mon, 19 Dec 2011 07:04:20 -0500, Bear joanylepri...@yahoo.fr wrote: Using D1, I have a program that creates tons of float[] ; for performance reasons, I would like them to be uninitialized. I've tried replacing float[] f = new float[x]; by float[] f = cast(float[])std.gc.malloc(x*4); this

Re: Void initialization

2011-12-19 Thread Bear
gc.malloc actually returns void[] Bearophile's suggestion seems to work though, but it doesn't seem to improve performance for some reason... I guess I'll have to find some other way to make my prog quicker.

Re: delegate, template and alias

2011-12-19 Thread Philippe Sigaud
On Mon, Dec 19, 2011 at 15:35, Heromyth bitwo...@qq.com wrote: Woo, I got it. What's the difference with your first post?

Re: delegate, template and alias

2011-12-19 Thread Timon Gehr
On 12/19/2011 06:46 PM, Philippe Sigaud wrote: On Mon, Dec 19, 2011 at 15:35, Heromythbitwo...@qq.com wrote: Woo, I got it. What's the difference with your first post? He uses an eponymous template now.

Allocating memory in D shared library when accessed from C++

2011-12-19 Thread Martin Drasar
Hello everyone, I would like to ask you about linking D shared objects (.dll and .so) from a C++ program. Say I have this C++ loader: typedef int (*MagicFunction) (); HMODULE handle = LoadLibraryA(DLibrary.dll); if (handle) { MagicFunction fn = (MagicFunction) GetProcAddress(handle,

Re: Void initialization

2011-12-19 Thread Jacob Carlborg
On 2011-12-19 18:24, Bear wrote: gc.malloc actually returns void[] Bearophile's suggestion seems to work though, but it doesn't seem to improve performance for some reason... I guess I'll have to find some other way to make my prog quicker. You can always make the variable uninitialized using

Re: Allocating memory in D shared library when accessed from C++

2011-12-19 Thread Andrej Mitrovic
Check if GetProcAddress returns null? It seems to me you're looking for _magicFunction but defining magicNumber, two different names.

Re: Void initialization

2011-12-19 Thread Steven Schveighoffer
On Mon, 19 Dec 2011 12:24:18 -0500, Bear joanylepri...@yahoo.fr wrote: gc.malloc actually returns void[] http://www.d-programming-language.org/phobos/core_memory.html#malloc Looks like void* to me... Or is there another function I'm not aware of? I think it should be GC.malloc, not

Re: newbie question: Can D do this?

2011-12-19 Thread simendsjo
On 19.12.2011 17:17, clk wrote: 1) Does D support something like the javascript 1.8 destructuring assigment (multiple assigment in python): [a, b] = [b, a]; I don't think so, but you can do something like this with templates: void swap(alias a, alias b)() { auto t = a; a = b; b =

Re: Allocating memory in D shared library when accessed from C++

2011-12-19 Thread Simon
On 19/12/2011 18:01, Andrej Mitrovic wrote: Check if GetProcAddress returns null? It seems to me you're looking for _magicFunction but defining magicNumber, two different names. that's be it. can't remember the rules for whether it will have a leading underscore, but you can always use

Re: newbie question: Can D do this?

2011-12-19 Thread Jonathan M Davis
On Monday, December 19, 2011 11:17:43 clk wrote: Hello, I'm new to this mailing list. I'm trying to learn D to eventually use it in production code. I'm a little bit intimidated by the fact that the topics in the d-learn list look rather advanced to a newbie like me. I have 3 fairly simple

Re: newbie question: Can D do this?

2011-12-19 Thread Ali Çehreli
On 12/19/2011 08:17 AM, clk wrote: I'm a little bit intimidated by the fact that the topics in the d-learn list look rather advanced to a newbie like me. We need more newbie topics here! :) 1) Does D support something like the javascript 1.8 destructuring assigment (multiple assigment in

Re: newbie question: Can D do this?

2011-12-19 Thread Kai Meyer
On 12/19/2011 09:17 AM, clk wrote: Hello, I'm new to this mailing list. I'm trying to learn D to eventually use it in production code. I'm a little bit intimidated by the fact that the topics in the d-learn list look rather advanced to a newbie like me. I have 3 fairly simple questions: 1) Does

Re: newbie question: Can D do this?

2011-12-19 Thread Simen Kjærås
On Mon, 19 Dec 2011 17:17:43 +0100, clk c...@clksoft.com wrote: Hello, I'm new to this mailing list. I'm trying to learn D to eventually use it in production code. I'm a little bit intimidated by the fact that the topics in the d-learn list look rather advanced to a newbie like me. I have 3

Re: newbie question: Can D do this?

2011-12-19 Thread Ali Çehreli
On 12/19/2011 10:39 AM, Jonathan M Davis wrote: it's a range (see http://www.informit.com/articles/printerfriendly.aspx?p=1407357 for a general explanation of the concept of ranges) That's a great article.[1] I hope that this chapter is more beginner-friendly:

Re: delegate, template and alias

2011-12-19 Thread Philippe Sigaud
On Mon, Dec 19, 2011 at 18:49, Timon Gehr timon.g...@gmx.ch wrote: On 12/19/2011 06:46 PM, Philippe Sigaud wrote: On Mon, Dec 19, 2011 at 15:35, Heromythbitwo...@qq.com  wrote: Woo, I got it. What's the difference with your first post? He uses an eponymous template now. Ah yes, thanks.

Re: Allocating memory in D shared library when accessed from C++

2011-12-19 Thread Martin Drašar
Dne 19.12.2011 19:39, Simon napsal(a): On 19/12/2011 18:01, Andrej Mitrovic wrote: Check if GetProcAddress returns null? It seems to me you're looking for _magicFunction but defining magicNumber, two different names. that's be it. can't remember the rules for whether it will have a leading

Re: Allocating memory in D shared library when accessed from C++

2011-12-19 Thread Trass3r
It actualy returns a procedure address and the procedure is called. It lands inside export extern (C) int magicNumber() and crashes when attempting to allocate memory for Something. Did you properly initialize druntime?

Re: Allocating memory in D shared library when accessed from C++

2011-12-19 Thread Martin Drašar
Dne 19.12.2011 23:09, Trass3r napsal(a): It actualy returns a procedure address and the procedure is called. It lands inside export extern (C) int magicNumber() and crashes when attempting to allocate memory for Something. Did you properly initialize druntime? As I am just starting with D,

Re: Allocating memory in D shared library when accessed from C++

2011-12-19 Thread Trass3r
Am 19.12.2011, 23:13 Uhr, schrieb Martin Drašar dra...@ics.muni.cz: Dne 19.12.2011 23:09, Trass3r napsal(a): It actualy returns a procedure address and the procedure is called. It lands inside export extern (C) int magicNumber() and crashes when attempting to allocate memory for Something.

Re: delegate, template and alias

2011-12-19 Thread Timon Gehr
On 12/19/2011 09:30 PM, Philippe Sigaud wrote: On Mon, Dec 19, 2011 at 18:49, Timon Gehrtimon.g...@gmx.ch wrote: On 12/19/2011 06:46 PM, Philippe Sigaud wrote: On Mon, Dec 19, 2011 at 15:35, Heromythbitwo...@qq.comwrote: Woo, I got it. What's the difference with your first post?

Re: Allocating memory in D shared library when accessed from C++

2011-12-19 Thread Martin Drašar
Dne 20.12.2011 0:02, Trass3r napsal(a): Am 19.12.2011, 23:13 Uhr, schrieb Martin Drašar dra...@ics.muni.cz: Dne 19.12.2011 23:09, Trass3r napsal(a): It actualy returns a procedure address and the procedure is called. It lands inside export extern (C) int magicNumber() and crashes when

Re: Void initialization

2011-12-19 Thread Jesse Phillips
On Mon, 19 Dec 2011 18:52:44 +0100 Jacob Carlborg d...@me.com wrote: You can always make the variable uninitialized using void, don't know if that what is what you're looking for. float[] f = void; He is trying to create an array where the elements are not initialized.

Re: Allocating memory in D shared library when accessed from C++

2011-12-19 Thread Andrej Mitrovic
test.cpp: http://www.ideone.com/uh7vN DLibrary.d: http://www.ideone.com/fOLN8 $ g++ test.cpp $ dmd -ofDLibrary.dll DLibrary.d $ a.exe $ 9

Re: newbie question: Can D do this?

2011-12-19 Thread Jakob Ovrum
On Monday, 19 December 2011 at 19:01:10 UTC, Simen Kjærås wrote: import std.typetuple : TypeTuple; import std.typecons : tuple; TypeTuple!(a, b) = tuple(b,a); There is a pull request implementing multiple variable declarations: https://github.com/D-Programming-Language/dmd/pull/341

Re: Void initialization

2011-12-19 Thread Jacob Carlborg
On 2011-12-20 01:34, Jesse Phillips wrote: On Mon, 19 Dec 2011 18:52:44 +0100 Jacob Carlborgd...@me.com wrote: You can always make the variable uninitialized using void, don't know if that what is what you're looking for. float[] f = void; He is trying to create an array where the