www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - just a few small questions

reply MM <MM_member pathlink.com> writes:
I'm really interested in using D for my next Game, but I had a few questions...

License:
First, can I use D commercially ... 
Why is there a open source frontend, or better: Why is D not opensource?
(no offence intended)

Status:
Is D ready for commercial use?
(I need OpenGl and SDL) 

implementation:
I'm really not into garbage collection(coming from C) and never had a real
understanding of tthe difference between stack and heap memory.
What is the best way to allocate a array like this:
info a[500][500];

info{
uint x,y,z;
}

thx, MM
Apr 14 2006
next sibling parent reply "Derek Parnell" <derek psych.ward> writes:
On Sat, 15 Apr 2006 10:01:41 +1000, MM <MM_member pathlink.com> wrote:

 I'm really interested in using D for my next Game, but I had a few  
 questions...
...
 implementation:
 I'm really not into garbage collection(coming from C) and never had a  
 real
 understanding of tthe difference between stack and heap memory.
 What is the best way to allocate a array like this:
 info a[500][500];

 info{
 uint x,y,z;
 }
module whatever; private { struct info { uint x,y,z; } info[500][500] a; } This should allocate the array of structs on the heap in a non-GC manner. One major difference from C arrays is that the indexes are *used* in the reverse order from C. Meaning that in C one would write ... item = a[X][Y]; but in D one writes ... item = a[Y][X]; -- Derek Parnell Melbourne, Australia
Apr 14 2006
next sibling parent reply MM <MM_member pathlink.com> writes:
  module whatever;
  private {
    struct info
    {
      uint x,y,z;
    }

    info[500][500] a;
  }

This should allocate the array of structs on the heap in a non-GC manner.

One major difference from C arrays is that the indexes are *used* in the  
reverse order from C. Meaning that in C one would write ...

    item = a[X][Y];

but in D one writes ...

    item = a[Y][X];

-- 
Derek Parnell
Melbourne, Australia
Thx, just one more question... I need to read alot of blocks(rectangles if seen as a plane) out of it like. Is this way then the fastest implementaion? And how much can I take from the heap without problems?
Apr 15 2006
parent reply MM <MM_member pathlink.com> writes:
I need to read alot of blocks(rectangles if seen as a plane) out of it like.
Is this way then the fastest implementaion?
And how much can I take from the heap without problems?
I'm sorry to for ask attention... but I really need some help here :( I just need one global array which is read like I said and one every few minutes filled with different data... is the stack the best place for this kind of data?
Apr 17 2006
parent reply clayasaurus <clayasaurus gmail.com> writes:
MM wrote:
 I need to read alot of blocks(rectangles if seen as a plane) out of it like.
 Is this way then the fastest implementaion?
 And how much can I take from the heap without problems?
I'm sorry to for ask attention... but I really need some help here :( I just need one global array which is read like I said and one every few minutes filled with different data... is the stack the best place for this kind of data?
I would tend to use the heap for large sets of data and the stack for local variables that you use only in the scope you use it in. I think you are best off using the heap for your large global array. Data placed on the heap stays there until you explicitly delete it, so you don't have to use a global. Heap is also what you use if you have any sort of dynamic memory needs, you can allocate what you need when you need it. If you use new/delete to much, the heap may become segmented and then the garbage collector will run (I think). The heap is unlimited for the most part, while you can only allocate so much data onto the stack. The heap might be slower to access, but not enough to be a significant problem. Maybe an expert can vindicate my post? ~ Clay
Apr 17 2006
parent reply MM <MM_member pathlink.com> writes:
I think you are best off using the heap for your large global array. 
Data placed on the heap stays there until you explicitly delete it, so 
you don't have to use a global. Heap is also what you use if you have 
any sort of dynamic memory needs, you can allocate what you need when 
you need it. If you use new/delete to much, the heap may become 
segmented and then the garbage collector will run (I think). The heap is 
unlimited for the most part, while you can only allocate so much data 
onto the stack. The heap might be slower to access, but not enough to be 
a significant problem.

Maybe an expert can vindicate my post?
~ Clay
Why is wrong with using a Global? When I need an array for the whole time and more than half of the subs need to access it, I just don't want to use those annoying pointers the whole time :).. how is this done in D?
Apr 18 2006
next sibling parent reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
MM wrote:
I think you are best off using the heap for your large global array. 
Data placed on the heap stays there until you explicitly delete it, so 
you don't have to use a global. Heap is also what you use if you have 
any sort of dynamic memory needs, you can allocate what you need when 
you need it. If you use new/delete to much, the heap may become 
segmented and then the garbage collector will run (I think). The heap is 
unlimited for the most part, while you can only allocate so much data 
onto the stack. The heap might be slower to access, but not enough to be 
a significant problem.

Maybe an expert can vindicate my post?
~ Clay
Why is wrong with using a Global? When I need an array for the whole time and more than half of the subs need to access it, I just don't want to use those annoying pointers the whole time :).. how is this done in D?
Pointers, schmointers. You can pass an array as normal to a function without copying. (This is where the Copy-on-Write people might speak up. I'll let them.) Also, if you intend to replace the array during a function, just use an 'out' or 'inout' parameter. Although personally I have no problem with using globals. :) -- Chris Nicholson-Sauls
Apr 18 2006
parent David Medlock <noone nowhere.com> writes:
Chris Nicholson-Sauls wrote:
 MM wrote:
 I think you are best off using the heap for your large global array. 
 Data placed on the heap stays there until you explicitly delete it, 
 so you don't have to use a global. Heap is also what you use if you 
 have any sort of dynamic memory needs, you can allocate what you need 
 when you need it. If you use new/delete to much, the heap may become 
 segmented and then the garbage collector will run (I think). The heap 
 is unlimited for the most part, while you can only allocate so much 
 data onto the stack. The heap might be slower to access, but not 
 enough to be a significant problem.

 Maybe an expert can vindicate my post?
 ~ Clay
Why is wrong with using a Global? When I need an array for the whole time and more than half of the subs need to access it, I just don't want to use those annoying pointers the whole time :).. how is this done in D?
Pointers, schmointers. You can pass an array as normal to a function without copying. (This is where the Copy-on-Write people might speak up. I'll let them.) Also, if you intend to replace the array during a function, just use an 'out' or 'inout' parameter. Although personally I have no problem with using globals. :) -- Chris Nicholson-Sauls
if by replace your mean modify the array itself, no 'out' is needed since arrays are passed by reference, just like objects. If you want to change the *variable* in the calling function, then an (in)out is needed. -DavidM
Apr 21 2006
prev sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"MM" <MM_member pathlink.com> wrote in message 
news:e23tmv$1gaq$1 digitaldaemon.com...
 Why is wrong with using a Global? When I need an array for the whole time 
 and
 more than half of the subs need to access it, I just don't want to use 
 those
 annoying pointers the whole time :).. how is this done in D?
Well, if you're programming in a C-style fashion, where you just have a bunch of global data and a bunch of functions to manipulate it.. I suppose it's kind of _messy_ and certainly not my preferred method, but there's nothing stopping _you_ from doing it :) One of the problems of using a large global array is that it's allocated in the static data segment. This isn't a problem if you just define int[500][500] x; But if you initialize any of it statically: int[500][500] x = [0 : [0 : 1]]; (which means set x[0][0] = 1) It makes the EXE size jump up quite a bit. In this case, by about 1MB. You can get around this by using static module constructors though: int[500][500] x; static this() { x[0][0] = 1; }
Apr 18 2006
prev sibling parent reply Bruno Medeiros <brunodomedeirosATgmail SPAM.com> writes:
Derek Parnell wrote:
 
 One major difference from C arrays is that the indexes are *used* in the 
 reverse order from C. Meaning that in C one would write ...
 
    item = a[X][Y];
 
 but in D one writes ...
 
    item = a[Y][X];
 
 --Derek Parnell
 Melbourne, Australia
This is not correct, I belive (or at leas mis-explained) . Only D array declaration and C array declaration have a different order. The array *usage*, or rather, the indexing of an array works the same. That is, in both C and D: //The X element is accessed first, and then the Y element is accessed item = a[X][Y]; -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Apr 15 2006
parent "Derek Parnell" <derek psych.ward> writes:
On Sun, 16 Apr 2006 04:28:45 +1000, Bruno Medeiros  
<brunodomedeirosATgmail SPAM.com> wrote:

 Derek Parnell wrote:
  One major difference from C arrays is that the indexes are *used* in  
 the reverse order from C. Meaning that in C one would write ...
     item = a[X][Y];
  but in D one writes ...
     item = a[Y][X];
  --Derek Parnell
 Melbourne, Australia
This is not correct, I belive (or at leas mis-explained) . Only D array declaration and C array declaration have a different order. The array *usage*, or rather, the indexing of an array works the same. That is, in both C and D: //The X element is accessed first, and then the Y element is accessed item = a[X][Y];
What I meant was in D if one declares ... int[Columns][Rows] A; then in D you access the elements as A[Row][Col]; and not A[Col][Row]; but in C (which I'm really very rusty in) you would declare int A[Rows][Columns]; and access it as A[Row][Col]; -- Derek Parnell Melbourne, Australia
Apr 15 2006
prev sibling next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"MM" <MM_member pathlink.com> wrote in message 
news:e1pd55$fjf$1 digitaldaemon.com...
 License:
 First, can I use D commercially ...
Yes.
 Why is there a open source frontend, or better: Why is D not opensource?
 (no offence intended)
The frontend is open source, but the backend is shared between D and Digital Mars's C++ compiler, DMC, which is a commercial product. If you want a fully open-source D compiler, look for GDC (though it isn't always completely up-to-date).
 Status:
 Is D ready for commercial use?
Maybe. There are still some issues which kind of need to be ironed out, but if you're willing to kind of ignore them ;) you could probably do fine.
 (I need OpenGl and SDL)
There are bindings to both on dsource, I believe.
Apr 14 2006
parent reply MM <MM_member pathlink.com> writes:
 Why is there a open source frontend, or better: Why is D not opensource?
 (no offence intended)
The frontend is open source, but the backend is shared between D and Digital Mars's C++ compiler, DMC, which is a commercial product. If you want a fully open-source D compiler, look for GDC (though it isn't always completely up-to-date).
Thx... but ehm, I can use D commercially but the backend? is a commercial product? Do I need to buy this? (I can't even find a page where I see any purchasing :D (backend = the actual compiler?)
There are bindings to both on dsource, I believe.
Is a binding just as fast as a 'normal' implementation?
Apr 15 2006
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"MM" <MM_member pathlink.com> wrote in message 
news:e1qt2l$26iq$1 digitaldaemon.com...
 Thx... but ehm, I can use D commercially but the backend? is a commercial
 product?
 Do I need to buy this? (I can't even find a page where I see any 
 purchasing :D
 (backend = the actual compiler?)
Oh no no, here's how it works: Walter (the guy who is Digital Mars) wrote DMC, the C compiler. It is made technically of two parts: the frontend, which turns the source code files into a sort of meta-format, and the backend, which turns the meta-format into a program. The reason this is built like this is that Walter can take the backend off the C compiler, write the D frontend (which is open-source), and make the D frontend produce a meta-format that the backend can understand. That way, half of his work is done for him - he doesn't have to write an entire second backend for the D compiler. The backend is part and parcel of the D compiler, but you don't have to pay anything for it, as D is not (yet) a commercial product. This is why there's a GDC compiler - the gnu compiler project has a backend specification, and people can write frontends for it. In the case of D, it's just a matter of making the D frontend (open-source) output a meta-format the the gnu backend can understand. The backend is not open-source, only because Walter is currently making money off of it by selling DMC. If he were to release the source of the backend, people would be able to make a compiler just like DMC for free, if they just wrote a C frontend. So in short, no, you don't have to pay a thing or worry about licensing or anything if you use D. And if you're still not sure about it, there's always GDC :)
 Is a binding just as fast as a 'normal' implementation?
A binding is just the interface to a library of some sort for a specific language. Most libraries come with C header files, and thus come with a C binding. Making a D binding of something usually just involves translating the header file(s) to D (since D is link-compatible with C). D interfaces with C code very well; there is no performance penalty.
Apr 15 2006
parent MM <MM_member pathlink.com> writes:
Thx! :)
That explained everything very clearly!
Apr 15 2006
prev sibling parent reply clayasaurus <clayasaurus gmail.com> writes:
MM wrote:
 I'm really interested in using D for my next Game, but I had a few questions...
 
 
 Status:
 Is D ready for commercial use?
D is in an advanced beta stage (not v1.0 status yet), and I would say yes, but there are some risks involved such as possible compiler bugs, lack of debugging options on windows, incomplete libraries, and possible language changes. However, for some, the amazing compile speeds and ease of use make up for its deficiencies. There are a number of large projects that have used D already, such as an EMCA script engine, GUI toolkits, some open source games, and more at www.dsource.org
 (I need OpenGl and SDL) 
http://www.dsource.org/projects/bindings http://www.dsource.org/projects/derelict
Apr 14 2006
parent reply MM <MM_member pathlink.com> writes:
D is in an advanced beta stage (not v1.0 status yet), and I would say 
yes, but there are some risks involved such as possible compiler bugs, 
lack of debugging options on windows, incomplete libraries, and possible 
language changes. However, for some, the amazing compile speeds and ease 
of use make up for its deficiencies. There are a number of large 
projects that have used D already, such as an EMCA script engine, GUI 
toolkits, some open source games, and more at www.dsource.org
Yeah I saw some japanese games made in D, they felt really solid which made me interested in D in the first place :)
 (I need OpenGl and SDL) 
http://www.dsource.org/projects/bindings http://www.dsource.org/projects/derelict
I get this message: FATAL: connection limit exceeded for non-superusers btw, which windows IDE do you propose?
Apr 15 2006
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"MM" <MM_member pathlink.com> wrote in message 
news:e1qtc1$26nd$1 digitaldaemon.com...
 Yeah I saw some japanese games made in D, they felt really solid which 
 made me
 interested in D in the first place :)
Oh, did you see them on a CD? Apparently, one of those was on a CD that came with CGW.
 I get this message:
 FATAL: connection limit exceeded for non-superusers
Ook, it looks like it's down or something.
 btw, which windows IDE do you propose?
Hm. There's no real D IDE at the moment.. they always seem to get kind of far and then the programmers give up on them (happened to DIDE and akIDE, and Elephant isn't moving too fast either). Personally I'd recommend ConTEXT (www.context.cx), I've been using it with D for over a year and I'm really happy with it. I could post a highlighter file for it, as the one on the download site for ConTEXT is a little outdated. ConTEXT, coupled with some kind of automated building system (like makefiles, Derek's build utility, or even just batchfiles (like I do ;) )), can be very nice indeed. I haven't missed much from Visual Studio.
Apr 15 2006
next sibling parent MM <MM_member pathlink.com> writes:
mm... think my post went wrong somewhere... I waited a half an hour..
(so excuse me for a double post,.. oh how I hate to say everything twice :D)

Oh, did you see them on a CD?  Apparently, one of those was on a CD that 
came with CGW.
Nop... just saw some nice games on some game sites probably.. Both Have really nice games on them.. written in D http://www.asahi-net.or.jp/~cs8k-cyu/index_e.html http://homepage2.nifty.com/isshiki/prog_win_d.html
Ook, it looks like it's down or something.
I'll check later on
Personally I'd recommend ConTEXT (www.context.cx), I've been using it with D 
for over a year and I'm really happy with it.  I could post a highlighter 
file for it, as the one on the download site for ConTEXT is a little 
outdated.  ConTEXT, coupled with some kind of automated building system 
(like makefiles, Derek's build utility, or even just batchfiles (like I do 
;) )), can be very nice indeed.  I haven't missed much from Visual Studio. 
Highlighting would be nice.. but maybe its even better to send yours to ConTEXT :D... I never did any manual compiling, so I'll look into those suggestion (after easter that is :D)
Apr 15 2006
prev sibling parent reply kris <foo bar.com> writes:
Jarrett Billingsley wrote:
 "MM" <MM_member pathlink.com> wrote in message 
 news:e1qtc1$26nd$1 digitaldaemon.com...
 
Yeah I saw some japanese games made in D, they felt really solid which 
made me
interested in D in the first place :)
Oh, did you see them on a CD? Apparently, one of those was on a CD that came with CGW.
I get this message:
FATAL: connection limit exceeded for non-superusers
Ook, it looks like it's down or something.
btw, which windows IDE do you propose?
Hm. There's no real D IDE at the moment.. they always seem to get kind of far and then the programmers give up on them (happened to DIDE and akIDE, and Elephant isn't moving too fast either). Personally I'd recommend ConTEXT (www.context.cx), I've been using it with D for over a year and I'm really happy with it. I could post a highlighter file for it, as the one on the download site for ConTEXT is a little outdated. ConTEXT, coupled with some kind of automated building system (like makefiles, Derek's build utility, or even just batchfiles (like I do ;) )), can be very nice indeed. I haven't missed much from Visual Studio.
I just downloaded conTEXT to give it a whirl -- it looks like a nice editor, but I don't see any place to remap the keyboard-commands. Is that the case? Thx; - Kris
Apr 15 2006
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"kris" <foo bar.com> wrote in message 
news:e1rbmj$2qjq$1 digitaldaemon.com...
 I just downloaded conTEXT to give it a whirl -- it looks like a nice 
 editor, but I don't see any place to remap the keyboard-commands. Is that 
 the case?
Yes, although that supposedly will be coming in the next update, as well as a much more powerful highlighting engine. Of course, no one knows when that is... :P
Apr 15 2006
prev sibling next sibling parent reply James Pelcis <jpelcis gmail.com> writes:
 I get this message:
 FATAL: connection limit exceeded for non-superusers
The links for the bindings project are http://www.summerseas.com/jpelcis/downloads/opengl.zip and http://www.summerseas.com/jpelcis/downloads/sdl.zip Hope they work for you!
Apr 15 2006
parent MM <MM_member pathlink.com> writes:
Hope they work for you!
Ay!.. thx!
Apr 17 2006
prev sibling parent clayasaurus <clayasaurus gmail.com> writes:
MM wrote:
 I get this message:
 FATAL: connection limit exceeded for non-superusers
 
Check back again in a day or two.
 btw, which windows IDE do you propose?
 
I myself like to use Poseidon on dsource ( www.dsource.org/projects/poseidon ), I've also heard of people being satisfied with Code Blocks IDE. Also, be sure to check out the build tool at www.dsource.org/projects/build as soon as dsource gets back online.
Apr 15 2006