compiled code file size

2013-09-20 Thread Duke Normandin
I'm re-visiting the D language. I've compared the file sizes of 2 
executables - 1 is compiled C code using gcc; the other is D code 
using dmd.


helloWorld.d = helloWorld.exe = 146,972 bytes
ex1hello.c = ex1-hello.exe = 5,661 bytes

Why such a huge difference???

Duke


Re: compiled code file size

2013-09-20 Thread Duke Normandin

On Friday, 20-Sep-13 11:28 AM, captaindet wrote:

On 2013-09-20 10:03, Duke Normandin wrote:

I'm re-visiting the D language. I've compared the file sizes of 2
executables - 1 is compiled C code using gcc; the other is D code
using dmd.

helloWorld.d = helloWorld.exe = 146,972 bytes
ex1hello.c = ex1-hello.exe = 5,661 bytes

Why such a huge difference???

Duke


maybe somehow related:

i have a short program using GtkD. the exe is
~3MB if compiled using dmd and linked to pre-built GtkD.lib (16MB)
~2MB if compiled via bud/build following up on all imports directly,
no linking to pre-built lib

all compiler flags the same (-debug for exe, prebuilt lib is not
debug but -O -inline -release). on windows.



interesting 



Re: compiled code file size

2013-09-20 Thread Duke Normandin

On Friday, 20-Sep-13 10:50 AM, Temtaime wrote:

C/C++ applications also carries on its runtime(mingwm10, msvc's
redist, for example).
If compiled with static runtime, msvc's hello world application uses
about 40 KB.


+1


Re: compiled code file size

2013-09-20 Thread Duke Normandin

On Friday, 20-Sep-13 10:45 AM, Adam D. Ruppe wrote:

On Friday, 20 September 2013 at 16:20:34 UTC, Duke Normandin wrote:

Why such a huge difference???


The D program carries its additional D runtime library code with it,
whereas the C program only depends on libraries provided by the
operating system, and thus it doesn't have to include it in the exe.


Now that I know _why_ , is there a way to shave tons off those 
executables? Any optimization possible?


Re: compiled code file size

2013-09-20 Thread Duke Normandin

On Friday, 20-Sep-13 10:49 AM, Dicebot wrote:

On Friday, 20 September 2013 at 16:20:34 UTC, Duke Normandin wrote:

I'm re-visiting the D language. I've compared the file sizes of 2
executables - 1 is compiled C code using gcc; the other is D code
using dmd.

helloWorld.d = helloWorld.exe = 146,972 bytes
ex1hello.c = ex1-hello.exe = 5,661 bytes

Why such a huge difference???

Duke


You are doing it wrong.
```
$ gcc hello.c; ls -lah a.out
-rwxr-xr-x 1 dicebot users 4.9K Sep 20 18:47 a.out
```
vs
```
$ gcc -static hello.c; ls -lah a.out
-rwxr-xr-x 1 dicebot users 717K Sep 20 18:48 a.out
```

(C standard library is dynamically linked by default)

So actual relative difference is about 2x - quite big but not as
huge. It mostly comes from additional D runtime stuff.


I get the same executable size whether or not I use `-static' with 
cygwin/win7 ...


Still tons smaller than the D executable though. Not good!! me young 
mucker  :D


Re: compiled code file size

2013-09-20 Thread Duke Normandin

On Friday, 20-Sep-13 3:04 PM, Nick Sabalausky wrote:

On Fri, 20 Sep 2013 21:45:48 +0200
Temtaime temta...@gmail.com wrote:


Software MUST
running almost ANYWHERE and consumes minimal resources.

For example i hate 3dsmax developers when on my game's map it
uses several GB of ram amd freezes sometimes, when Blender uses
only 500 MB and runs fast. The only reason for me for use 3dsmax
is more friendly contoling. But this is another story...

Some users which doesn't have modern PC will hate your app
too i think.
One should optimize ALL things which he can to optimize.



I agree with what you're saying here, but the problem is we're looking
at a difference of only a few hundred k.

Heck, my primary PC was a 32-bit single-core right up until last year
(and I still use it as a secondary system), and I didn't care one bit if
a hello world was 1k or 1MB.

How many real world programs are as trivial as a hello world? A few
maybe, but not many. Certainly not enough to actually add up to
anything significant, unless maybe you happen to be running on a 286 or
such.

If we were talking about real-world D programs taking tens/hundreds of
MB more than they should, then that would be a problem. But they
don't. We're just talking about a few hundred k for an *entire* program.



I should have been a bit more clear!! It's the _relative_ size 
difference that bothers me!! One is almost 26 times larger than the 
other. If I'm to expect that same variance in a large to huge 
project, that I think that I'd me in a world of bullshine!!


Re: compiled code file size

2013-09-20 Thread Duke Normandin

On Friday, 20-Sep-13 2:20 PM, H. S. Teoh wrote:

On Fri, Sep 20, 2013 at 11:26:18AM -0600, Duke Normandin wrote:

On Friday, 20-Sep-13 10:45 AM, Adam D. Ruppe wrote:

On Friday, 20 September 2013 at 16:20:34 UTC, Duke Normandin wrote:

Why such a huge difference???


The D program carries its additional D runtime library code with it,
whereas the C program only depends on libraries provided by the
operating system, and thus it doesn't have to include it in the exe.


Now that I know _why_ , is there a way to shave tons off those
executables? Any optimization possible?


If you're on Linux:

dmd -release -O myprogram.d
strip myprogram
upx myprogram

I've seen this reduce a 50MB executable down to about 400k. YMMV.

Keep in mind, though, that stripping basically deletes all debugging
information from the executable (plus a bunch of other stuff -- you
don't want to do this to an object file or a library, for example), so
it's not something you want to do during development. And upx turns your
executable into something that probably violates the ELF spec in many
different ways, but resembles it closely enough that the kernel will
still run it. File type recognizers like 'file' may fail to recognize
the result as an executable afterwards. But it will still work. (That's
how cool upx is, in case you don't already know that.)


Thx!  I'll have to do some experimenting ...



Re: compiled code file size

2013-09-20 Thread Duke Normandin

On Friday, 20-Sep-13 11:59 AM, JohnnyK wrote:

On Friday, 20 September 2013 at 16:20:34 UTC, Duke Normandin wrote:

I'm re-visiting the D language. I've compared the file sizes of 2
executables - 1 is compiled C code using gcc; the other is D code
using dmd.

helloWorld.d = helloWorld.exe = 146,972 bytes
ex1hello.c = ex1-hello.exe = 5,661 bytes

Why such a huge difference???

Duke


That 140KB is called the CYA document.  It is there so that when you
the programmer screws up you don't look so bad in front of your boss.



[quote]CYA document ...[/quote]

sounds about right!!! :)


noob Q: declaring string variables

2010-05-29 Thread Duke Normandin
Back again...

As an introductory tutorial, I'm now using:

http://www.dsource.org/projects/tutorials/wiki/InitializingVariablesExample

BTW, somebody fix that page - the `writefln' statements are missing
the %d and %s.

char[] password = sesame;

didn't work on my MacOS X box. Why?

[sidebar]
Why is every D tutorial I've touched upon so far, been frigged up?
This is NOT good advocacy, people! Bad advertising! Where is the good
stuff hiding? L8r...

-- 
duke


noob Q: array out-of-range

2010-05-28 Thread Duke Normandin
Hey...

Compiler is now working as expected! Thank's to a great catch by
Michel Fortin!

A little further down the tutorial D_ A Newbie-Oriented Tutorial,
there's this code:

[code]
import std.stdio;

void main()
{
int[] intArray;

  intArray[0] = 42;
  intArray[1] = 54;
  intArray[2] = 91;

  writefln(The lemgth of the intArray is %d.,
 intArray.length);
}
[/code]

It compiles with no error or warning - AFAICT. However, it chokes
upon execution with:

dnormandin@ ~/programming/dmd2/code
01:40 pm  arrays_in_d
core.exception.rangeer...@arrays_in_d(7): Range violation

I've read and re-read the tutorial content, but it's not jumping out
at me.
-- 
duke


Re: noob Q: array out-of-range

2010-05-28 Thread Duke Normandin
On Fri, 28 May 2010, bearophile wrote:

 Don:
  The array initially has length of zero.
  You need to write something like:
  intArray = new int[3];
  or
  intArray.length = 3;
  before putting anything into it.

 In some languages (Perl? Maybe Lua and PHP) arrays auto-create empty slots as 
 needed, but in many languages you need to tell the language that you want 
 some empty slots before you can put values inside them (this stricter 
 behaviour can probably catch some bugs, and allows to produce faster 
 programs).

 Another way to add items to a D dynamic array like intArray is to append them 
 at the end, the language runtime takes care of creating new slots as needed:

 int[] intArray;
 intArray ~= 1;
 intArray ~= 2;
 intArray ~= 3;

 Bye,
 bearophile


@Don
@bearophile

Would you guys visit this URL real quick

http://compsci.ca/v3/viewtopic.php?t=9518

This is the site that I'm using to learn D. If you scroll down 3-4
screens full, you'll come to the array topic. Is this tutorial
outdated, wrong, or what, because it doesn't deem to sync with what
you two fine fellows are telling me about creating dynamic arrays in
the D-Language. TIA..
-- 
duke


Re: noob Q: array out-of-range

2010-05-28 Thread Duke Normandin
On Fri, 28 May 2010, bearophile wrote:

 Duke Normandin:

  This is the site that I'm using to learn D. If you scroll down 3-4
  screens full, you'll come to the array topic. Is this tutorial
  outdated, wrong, or what, because it doesn't deem to sync with what
  you two fine fellows are telling me about creating dynamic arrays in
  the D-Language. TIA..

 That part of that tutorial is not outdated, as far as I know it's just wrong.
 You can auto-create slots in associative arrays:

 int[int] aa;
 aa[0] = 1;
 aa[1] = 1;
 aa[2] = 1;

 Lua language uses associative arrays instead of arrays :-)

 Bye,
 bearophile



So these two paragraphs in the tutorial are flat out wrong?

[quote]
You should note that I never specified how long the array should be.
Instead I simply assigned values to various positions in the array and
it just worked.
This is an example of a dynamic array. It will grow to whatever size
is required. I can determine the size of an array at any time by
accessing the array's length property. The length property can also
have a value assigned to it to resize the array.
[/quote]

Maybe the link for this tutorial at:

http://www.prowiki.org/wiki4d/wiki.cgi?FirstLanguage

should be removed?

-- 
duke


Re: noob Q: array out-of-range

2010-05-28 Thread Duke Normandin
On Sat, 29 May 2010, Simen kjaeraas wrote:

 Duke Normandin dukeofp...@ml1.net wrote:

  So these two paragraphs in the tutorial are flat out wrong?

 Absolutely.

Then I'm done with _that_ site - can't trust it!

Any chance that you could suggest a good beginner's D tutorial?

-- 
duke


Re: Installing D on MacOS X Leopard box

2010-05-25 Thread Duke Normandin
On Tue, 25 May 2010, Nick Sabalausky wrote:

 Duke Normandin dukeofp...@ml1.net wrote in message
 news:mailman.43.1274754397.24349.digitalmar...@puremagic.com...
  Hello list...
 
  I'm new to D, but not programming.

 Welcome to D :)

Thank you!

  I've followed the instructions on
 
  http://www.digitalmars.com/d/2.0/dmd-osx.html
 
  However, I keep on getting this error:
 
  dnormandin@ ~/programming/dmd2/code
  04:38 pm  dmd -w firstApp.d
  object.d: Error: module object is in file 'object.d' which cannot be
  read
  import path[0] = /etc/../../src/phobos
  import path[1] = /etc/../../src/druntime/import
 
  My guess is that dmd.conf is hosed somehow. I haven't edited the
  default one - I've got it living in /etc/.
  --
  Duke

 Looks like those instructions need to be fixed.

I'm glad that in my noobiness, I've been able to contribute
_something_ ;)

 The file dmd.conf is expecting to live in the same directory as the DMD
 executable (ie, {wherever you unzipped DMD}/osx/bin/ ). Deleting it out of
 /etc/ should work. Or, if you really wanted, you could edit it (it's a
 pretty simple text file) and change the paths to point to the right places
 (Just replace %...@p% with {wherever you unzipped DMD}/osx/bin/)

Kinda thought so - but thought I'd ask first, _before_ I started
hacking and chopping.

 BTW, these sorts of things are probably best asked over in
 digitalmars.D.learn.

Thanks for the heads-up!
-- 
Duke


Re: Installing D on MacOS X Leopard box

2010-05-25 Thread Duke Normandin
On Tue, 25 May 2010, Michel Fortin wrote:

 On 2010-05-24 21:56:55 -0400, Duke Normandin dukeofp...@ml1.net said:

  Hello list...
 
  I'm new to D, but not programming. I've followed the instructions on
 
  http://www.digitalmars.com/d/2.0/dmd-osx.html
 
  However, I keep on getting this error:
 
  dnormandin@ ~/programming/dmd2/code
  04:38 pm  dmd -w firstApp.d
  object.d: Error: module object is in file 'object.d' which cannot be
  read
  import path[0] = /etc/../../src/phobos
  import path[1] = /etc/../../src/druntime/import
 
  My guess is that dmd.conf is hosed somehow. I haven't edited the
  default one - I've got it living in /etc/.

 If you want to avoid the hassle of installing things manually, you can also
 use the D for Xcode installer which, in addition to installing a plugin for
 Xcode, downloads and installs the latest version of DMD 1 and 2.

 http://michelf.com/projects/d-for-xcode/

Have it already - thanks! However, _now_ I need a tutorial on how to
use XCode, cuz I've been using emacs forever. I dabbled in ObjC for
awhile, but never got anywhere with, because I spent most of my time
keeping XCode happy. I don't want that to happen with my D
experience. Do you know of a _real good_ XCode tutorial?
-- 
Duke


Re: Installing D on MacOS X Leopard box

2010-05-25 Thread Duke Normandin
On Tue, 25 May 2010, Jacob Carlborg wrote:

 On 2010-05-25 03.56, Duke Normandin wrote:
  Hello list...
 
  I'm new to D, but not programming. I've followed the instructions on
 
  http://www.digitalmars.com/d/2.0/dmd-osx.html
 
  However, I keep on getting this error:
 
  dnormandin@ ~/programming/dmd2/code
  04:38 pm  dmd -w firstApp.d
  object.d: Error: module object is in file 'object.d' which cannot be
  read
  import path[0] = /etc/../../src/phobos
  import path[1] = /etc/../../src/druntime/import
 
  My guess is that dmd.conf is hosed somehow. I haven't edited the
  default one - I've got it living in /etc/.

 You can just unzip the zip file, add executable permission on dmd/osx/bin/dmd
 and use it just where it is.

dnormandin@ ~/programming/dmd2/osx/bin
07:53 am  ./dmd ../../code/firstApp.d
ld warning: in /usr/local/gnat/lib/libgcc_s.10.5.dylib, missing
required architecture i386 in file
ld warning: in
/usr/local/gnat/lib/gcc/x86_64-apple-darwin9.6.0/4.3.4/libgcc.a, file
is not of required architecture

Now what?
-- 
duke


Re: Installing D on MacOS X Leopard box

2010-05-25 Thread Duke Normandin
On Tue, 25 May 2010, Jacob Carlborg wrote:

 On 2010-05-25 15.55, Duke Normandin wrote:
  On Tue, 25 May 2010, Jacob Carlborg wrote:
 
   On 2010-05-25 03.56, Duke Normandin wrote:
Hello list...
   
I'm new to D, but not programming. I've followed the instructions on
   
http://www.digitalmars.com/d/2.0/dmd-osx.html
   
However, I keep on getting this error:
   
dnormandin@ ~/programming/dmd2/code
04:38 pm   dmd -w firstApp.d
object.d: Error: module object is in file 'object.d' which cannot be
read
import path[0] = /etc/../../src/phobos
import path[1] = /etc/../../src/druntime/import
   
My guess is that dmd.conf is hosed somehow. I haven't edited the
default one - I've got it living in /etc/.
  
   You can just unzip the zip file, add executable permission on
   dmd/osx/bin/dmd
   and use it just where it is.
 
  dnormandin@ ~/programming/dmd2/osx/bin
  07:53 am  ./dmd ../../code/firstApp.d
  ld warning: in /usr/local/gnat/lib/libgcc_s.10.5.dylib, missing
  required architecture i386 in file
  ld warning: in
  /usr/local/gnat/lib/gcc/x86_64-apple-darwin9.6.0/4.3.4/libgcc.a, file
  is not of required architecture
 
  Now what?

 What have you done with your developer tools installation ?? It doesn't
 install anything in /usr/local by default. And by default all libraries are
 universal binaries so you shouldn't have that problem.

 It seems you have installed a new gcc version and you haven't build it the
 Apple way, that is building with support for universal builds.

I simply followed the installation instructions on:

http://www.digitalmars.com/d/2.0/dmd-osx.html

I also installed the XCode plugin for D. Could _that_ have hosed my
install?
-- 
duke


Re: Installing D on MacOS X Leopard box

2010-05-25 Thread Duke Normandin
On Tue, 25 May 2010, Michel Fortin wrote:

 On 2010-05-25 09:19:01 -0400, Duke Normandin dukeofp...@ml1.net said:

  On Tue, 25 May 2010, Michel Fortin wrote:
 
   If you want to avoid the hassle of installing things manually, you can
   also
   use the D for Xcode installer which, in addition to installing a plugin
   for
   Xcode, downloads and installs the latest version of DMD 1 and 2.
  
   http://michelf.com/projects/d-for-xcode/
 
  Have it already - thanks! However, _now_ I need a tutorial on how to
  use XCode, cuz I've been using emacs forever. I dabbled in ObjC for
  awhile, but never got anywhere with, because I spent most of my time
  keeping XCode happy. I don't want that to happen with my D
  experience. Do you know of a _real good_ XCode tutorial?

 First, you don't *need* Xcode. The D for Xcode installer installs DMD so it is
 usable on the command line. You shouldn't have any problem using emacs, make,
 and whatever else you may like. If the 'dmd' command doesn't work after
 install, then it's probably something else outside of the DMD installation
 that is causing problems.

Never had a problem with gcc and all the other tools before I
installed D...

 Second, most Xcode tutorials focus on Cocoa and writing GUI applications. I'm
 not sure what you want to know, but personally what I find quite useful to be
 aware of is how the build system works. If that's what you want to learn,
 perhaps this is what you should read:
 http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/XcodeBuildSystem/

That URL is exactly what I've been looking for. Thanks.
-- 
duke


Re: Installing D on MacOS X Leopard box

2010-05-25 Thread Duke Normandin
On Tue, 25 May 2010, Michel Fortin wrote:

 On 2010-05-25 10:30:44 -0400, Duke Normandin dukeofp...@ml1.net said:

  I simply followed the installation instructions on:
 
  http://www.digitalmars.com/d/2.0/dmd-osx.html
 
  I also installed the XCode plugin for D. Could _that_ have hosed my
  install?

 Unlikely. The two errors you wrote about:

   dnormandin@ ~/programming/dmd2/osx/bin
   07:53 am  ./dmd ../../code/firstApp.d
   ld warning: in /usr/local/gnat/lib/libgcc_s.10.5.dylib, missing
   required architecture i386 in file
   ld warning: in
   /usr/local/gnat/lib/gcc/x86_64-apple-darwin9.6.0/4.3.4/libgcc.a, file
   is not of required architecture

 Noticed that both refer to files in /usr/local/gnat? GNAT, isn't this a
 GCC-based ADA compiler? My guess is that some of you environment variables
 have the /usr/local/gnat path before the standard system path, and gnat
 seems to include single-architecture (x86_64) copies of the GCC libraries. If
 that's the case, GCC running in 64 bit will work using these libraries, but
 since DMD is 32 bit it won't.

Nice catch! You must be French! ;) (like me..) Have to go out of town
for a few days, so I'll get back to this stuff at the end of the
week. L8r..
-- 
duke


Installing D on MacOS X Leopard box

2010-05-24 Thread Duke Normandin
Hello list...

I'm new to D, but not programming. I've followed the instructions on

http://www.digitalmars.com/d/2.0/dmd-osx.html

However, I keep on getting this error:

dnormandin@ ~/programming/dmd2/code
04:38 pm  dmd -w firstApp.d
object.d: Error: module object is in file 'object.d' which cannot be
read
import path[0] = /etc/../../src/phobos
import path[1] = /etc/../../src/druntime/import

My guess is that dmd.conf is hosed somehow. I haven't edited the
default one - I've got it living in /etc/.
-- 
Duke