   Saving space
  Hi all,I was wondering how can I save space in final binaries of my application.Could these -for example- be solutions?- using int instead of long- create less structures- using smart algorithmsthank you.   
  I'm a beginner myself, but I'd say always use the smallest type size that will correctly store your data, so yes: ints, short ints, bools... whatever is the minimum size that will work with your code.  Will probably make it quicker too   ;  * Procedurally generate your content* Use a exe compressor like UPX   ;Quote:Original post by tonywattsI'm a beginner myself, but I'd say always use the smallest type size that will correctly store your data, so yes: ints, short ints, bools... whatever is the minimum size that will work with your code.  Will probably make it quicker tooUsing smaller types will not necessarily speed up your code, and may in fact detract from performance. You should always use ints when appropriate. For example, on a 32 bit architecture an int is usually 32 bits. This is good, because your processor works in 32-bit chunks. Using smaller types will require alignment which may hurt performance.Worry about space saving when sending information out over a network or saving it to a disk (or, I suppose, writing for a mobile platform with severe space restrictions), not when choosing a variable type.   ;  I think that using "smaller" types (eg float rather than double) will only decrease memory usage. Besides, even if it did affect file size, it would be by about 4 bytes off the filesize whereas once you run the program and if it were to allocate 1000 of a structure that uses float instead of double in memory, that would be 4000 bytes off of memory usage. So using "smaller" variable sizes is for memory usage not file size.   ;  When I converted one of my projects from VS6 to VS2005, the size went from about 160K to about 1.5MB. I tracked it down to a single static array that VS2005 obviously decided to put in the apps static data initialistion segment. Newing up the array instead of having it global droped the size right back down. Anything else I could do would only make a couple of K difference at most.So, first off, are there any large global arrays?Next, there is a fantastic tool for compressing executables called UPX. Google it!   ;Quote:Original post by ClawerI was wondering how can I save space in final binaries of my application.Could these -for example- be solutions?- using int instead of longNo.  This reduces runtime memory use, except in the case of constants, but even then you're talking about 4 bytes out of millions.Quote:- create less structuresDepends on the language, but generally no.  Many languages these days that require a virtual machine or a JIT compiler of some sort store their structures with accompanying meta-data.  C/C++/compiled languages do not do this at all, and hardwire in the offsets to variables within a memory chunk.  In general though, the space you're saving by reducing the structure count compared to the space you're using with actual code [this could actually increase your file size, since you're likely going to have to be doing an awful lot of type-checking, which means storing RTTI information and the associated runtime performance hit].Quote:- using smart algorithmsdepends on what you mean by 'smarter'.  An algorithm that solves general problems will take up less space than several algorithms that solve specific problems.  But even then, this isn't where the majority of your executable size is coming from.  The majority of your code size is coming from the libraries you include/use, certain feature gotcha's within each language[like, for example, templates in C++ have a tendency of adding huge amounts of an executable], and the language you're using.  If you're using a compiled language[C/C++, etc], many compilers will include options of optimizing your code for certain purposes [like optimizing for speed, size, compilation speed, etc].  The compiler gets the last say in your file size anyway, and it can do a LOT to tighten it down.  For interpreted/JIT/scripting languages [including in this case, C#,Java, and all the usual suspects like python scripts and the like], there is less you can do, and less control that you'll have, since these languages have to store data about the data they're storing, or store very verbose versions of the source code [in the case of many script langs].  It's worth pointing out too that many of the typically not-compiled languages now have options compile.  My experience is limited in this particular area, so I can't say which languages have these abilities and which do not, but these compilation processes likely have similar options to traditional compilers [like reducing binary size].For saving space, it's important to consider what is taking up space in the first place [which is hard to put a finger on without what language you're using].In general though, unless you're coding for a cell phone or something similar, this isn't something you need to concern yourself with at all.  An extra 30 seconds of download time for a user in exchange for 30 weeks less development time, and/or 30% speed decrease.... Use what gets it done on time, and use what makes it run fast.   ;  I see from your other post that you are developing mobile phone apps.  In this case you should be using bytes wherever possible.  This won't reduce your final class size but it will reduce the amount of heap space the application takes up.Do you use a preprocessor?If so some nasty use of this can help you reduce your class size dramatically.  If you have gone "class happy" remember that although OOP and design is really good for large (and even small) projects.  On a mobile phone we don't have that luxary.  Try to stick everything in as few classes as possible.  Each seperate class adds about 2k extra.Try to reuse variables too.   ;  I see from your other post that you are developing mobile phone apps.  In this case you should be using bytes wherever possible.  This won't reduce your final class size but it will reduce the amount of heap space the application takes up.Do you use a preprocessor?If so some nasty use of this can help you reduce your class size dramatically.  If you have gone "class happy" remember that although OOP and design is really good for large (and even small) projects.  On a mobile phone we don't have that luxary.  Try to stick everything in as few classes as possible.  Each seperate class adds about 2k extra.Try to reuse variables too.   