|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
size of executable
Hi, I've just written my first few apps and they seem to be quite big. One for instance is 105kb, when all I'm including is <string>
and <fstream> (the source file itself is only 40 or so lines). Is this just how it is or can the compiler somehow remove unneeded functions? I'm using dev-c++. While I'm here, I want to change a files extension so I've done this: Code:
while(file_name[a] != '.'){
out_file[a] = file_name[a];
a++;
}
out_file[a] = '.';
a++;
out_file[a] = 't';
a++;
out_file[a] = 'p';
a++;
out_file[a] = 'l';
a++;
out_file[a] = '\0';
a++;
|
|
#2
|
||||
|
||||
|
Are you building debug binaries (bigger) or release binaries (smaller)?
__________________
Jon Sagara "Me fail English? That's unpossible!" |
|
#3
|
|||
|
|||
|
normal, it comes out at 280 with debug on.
I also have the optimize options on ( -g3 -fexpensive-optimizations) |
|
#4
|
|||
|
|||
|
include string and fstream will bloat the code considerably. These include files typically contain most of the code necessary to implement the class.
You can also simplify the code, by using C functions instead of C++ classes: Code:
#include <string.h>
#include <stdlib.h>
char* change_extension(char* filename) {
char* outfile;
char* extension;
outfile = (char *)calloc(1, strlen(filename) + 3);
strcpy(outfile, filename);
extension = strchr(outfile, '.');
if (extension)
strcpy(extension, ".tpl");
else
strcat(outfile, ".tpl");
return outfile;
}
The standard C libraries have a great set of functions for basic string manipulation and navigation. I usually find them to be easier to use than the C++ equivalents, with the exception of the search and replace capabilities of C++ strings.
__________________
Clay Dowling Lazarus Notes Articles and commentary on web development http://www.lazarusid.com/notes/ |
|
#5
|
|||
|
|||
|
Thanks, I think I just about get that piece of code you posted after some thought.
This line: Code:
outfile = (char *)calloc(1, strlen(filename) + 3); I understand to be allocating some space for the filename and adding some incase there's no extension (would that not need 4 then?) As to my first question, I did think about maybe trying C headers instead although I will need to read up on them (I tried changing to string to string.h and my compiler was not happy). All I'm doing with string is holding the line from the in file, checking it and then sending it out so maybe I can do something else and use C file I/O instead and see if that comes out smaller. Cheers then I'll give that a go. |
|
#6
|
|||
|
|||
|
You are right about the size: 4 bytes, not 3.
The calloc function, as you indicate, allocates memory. It also initializes all members to 0, which can save problems. The parameters to calloc are the number of records and the size of those records. Elsewhere in your program (but not in this function), you'll want to free() the memory after you're done with it, to prevent memory leaks. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > size of executable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|