C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 21st, 2002, 11:10 AM
mitsubishi mitsubishi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: England, UK
Posts: 35 mitsubishi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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++;
which seems a little odd, is there a tidier way. BTW I come from PHP and pointers scare me so I've no idea how I even managed that, so go easy.

Reply With Quote
  #2  
Old November 21st, 2002, 11:16 AM
jonsagara's Avatar
jonsagara jonsagara is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: USA
Posts: 286 jonsagara User rank is Private First Class (20 - 50 Reputation Level)jonsagara User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 m 23 sec
Reputation Power: 7
Are you building debug binaries (bigger) or release binaries (smaller)?
__________________
Jon Sagara

"Me fail English? That's unpossible!"

Reply With Quote
  #3  
Old November 21st, 2002, 11:24 AM
mitsubishi mitsubishi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: England, UK
Posts: 35 mitsubishi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
normal, it comes out at 280 with debug on.

I also have the optimize options on ( -g3 -fexpensive-optimizations)

Reply With Quote
  #4  
Old November 22nd, 2002, 10:11 AM
ClayDowling ClayDowling is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Flint, MI
Posts: 328 ClayDowling User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 25 sec
Reputation Power: 6
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/

Reply With Quote
  #5  
Old November 22nd, 2002, 11:12 AM
mitsubishi mitsubishi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: England, UK
Posts: 35 mitsubishi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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.

Reply With Quote
  #6  
Old November 22nd, 2002, 11:20 AM
ClayDowling ClayDowling is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Flint, MI
Posts: 328 ClayDowling User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 25 sec
Reputation Power: 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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > size of executable


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT