LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-25-2004, 04:15 AM   #1
nibbler
Member
 
Registered: Oct 2003
Location: Croatia
Distribution: Fedora 4
Posts: 46

Rep: Reputation: 15
a.out too big


Hi!

This code
Code:
int array[4000000]={0};

int main()
{
	return 0;
}
compiled with 'g++ temp.cpp' produces a.out file 15Mb big, which is the amount of memory to be allocated.

Code:
#include <stdlib.h>

int main()
{
	int *array=(int*)malloc(sizeof(int)*4000000);
	return 0;
}
a.out is now 11K.

Anyone knows why this is so?

I'm using Red Hat 9, gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5).

Thanks in advance
 
Old 05-25-2004, 05:04 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Your example illustrates the difference between statically and dynamically allocated memory.
In the first example, the int array is already in the binary while in the second one, the array is created at runtime.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Big O, Big Omega, and Big Theta oulevon Programming 7 05-26-2010 07:18 AM
Big, big hard drive in a little, little tablet... pengyou Linux - Laptop and Netbook 6 10-18-2004 03:44 AM
Big, big Problem on vsftpd rhonneil Linux - Newbie 1 10-01-2003 02:18 PM
Installing RH 9 with RAID 5 --Big, big Problem!!! rhonneil Linux - Software 2 09-25-2003 08:13 PM
big BIG javascript & loading time luigi Programming 3 09-10-2001 03:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration