From: Luke D. <cod...@ho...> - 2003-05-22 11:13:06
|
I am fairly sure that iostreams make all the difference. Try putting a 'cout << "Hello world!" << endl' in your list.cpp and see what you get. I would expect std::set to be smaller than all the I/O classes so it is not all that surprising (and the size of your actual code in main() would be insignificant). Luke ----- Original Message ----- From: "Anders Lindén" <Min...@li...> To: <Min...@li...> Sent: Thursday, May 22, 2003 6:20 PM Subject: [Mingw-users] Unpredictable exe-file sizes (totally weird) > Hello again. > I have two projects, > > project 1: > > filename: test.cpp > Lines: 8 > compilation cmdline: g++ test.cpp -o test.exe > description: writes "hello world" on the screen > resulting exefile size: 448537 bytes. After I have used the "strip" utility, it becomes 210944 bytes > > project 2: > filename: list.cpp > Lines: 54 > compilation cmdline: g++ list.cpp -lpsapi -o listprocesses.exe > description: Aquires a process token to get "debug" privilege, enumerates the processes and put the process ID:s in a std::set, > which results > in that they get sorted. Then it loops through the set and opens each of the processes and gets its filename, which it writes out > together with the > process ID. > resulting exefile size: 123746 bytes. After I have used the "strip" utility, it becomes 60416 bytes > > > Ok, now the question is, how can project 1 possibly get bigger than project 2? > My compiler is: MinGW-2.0.0-3 > > > test.cpp and list.cpp follows: > > > > test.cpp: > ======================================== > #include <iostream> > > using namespace std; > > int main() > { > cout << "Hello world!" << endl; > return 0; > } > > > > list.cpp: > ======================================== > #include <stdio.h> > #include <windows.h> > #include <psapi.h> > #include <set> > > using namespace std; > > set<DWORD> processes; > > int main() > { > char buffer[4096]; > HANDLE handle; > DWORD array[4096]; > DWORD arraysize; > HANDLE accesstoken; > TOKEN_PRIVILEGES tkp; > > /* Try to get some more influence */ > handle=GetCurrentProcess(); > if (OpenProcessToken(handle, > TOKEN_ADJUST_PRIVILEGES, > &accesstoken)) > { > if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid)) > { > tkp.PrivilegeCount=1; > tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; > AdjustTokenPrivileges(accesstoken, FALSE, &tkp, sizeof(tkp), NULL, NULL); > } > CloseHandle(accesstoken); > } > > if (!EnumProcesses( array ,4096*sizeof(DWORD),&arraysize)) > return fputs("Too many processes to enumerate (>4096)\n",stderr),1; > int numprocesses=arraysize/sizeof(DWORD); > for (int i=0; i<numprocesses; i++) > processes.insert(array[i]); > set<DWORD>::iterator iter; > for (iter=processes.begin(); iter!=processes.end(); iter++) > { > if ((handle=OpenProcess(PROCESS_ALL_ACCESS,FALSE,*iter))==NULL) > printf("%d\t\n",*iter); > else > { > if (GetModuleBaseName(handle,NULL,buffer,4096)>0) > printf("%d\t%s\n",*iter,buffer); > else > printf("%d\t-\n",*iter); > CloseHandle(handle); > } > } > return 0; > } > > > > > /Anders Lindén |