GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-May-2005, 22:39
kai85 kai85 is offline
...is NOT a boy!
 
Join Date: Jan 2005
Posts: 58
kai85 is on a distinguished road

runtime, compile time...


can someone please explain the difference between run time and compile time for me ( in an easy understandable way.)
  #2  
Old 19-May-2005, 06:59
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hello kai85. I am not sure of the official or school definition, but I can tell you the meaning that it has for me.

When you declare a variable, you have the option of allocating memory for that variable at compile time or at run time. For example, let's take an array. Suppose that you want work with 2-d matrices. So in your program, you would define:

CPP / C++ / C Code:
int matrix[100][100];

That would give you a 100x100 matrix of integers and it can not be changed unless you change your program and recompile it. This is known as compile time memory allocation. Right or wrong, I ussually refer to this as a static definition. Beyond, that it can't be changed, there is also some differences of how & where the memory is allocated and in addition it can not be "free'd" until the program is over.

Now, for the next example:
CPP / C++ / C Code:
int** matrix;

printf("How big would you like your matrix? ");
//get the number the using something like fgets & atoi
matrix = (int**) malloc( sizeof(int) * number * number);
This is run-time memory allocation. In C, you would use the malloc command and in C++ you would use the new command. Again, right or wrong, I call this dynamic memory allocation. I can make this any size I want, delete it, resize it, etc. all during program execution without recompiling. Thus it is run-time memory allocation.

There may be more to it than that, but that is my basic understanding.

HTH,
d
  #3  
Old 19-May-2005, 22:05
kai85 kai85 is offline
...is NOT a boy!
 
Join Date: Jan 2005
Posts: 58
kai85 is on a distinguished road
Quote:
Originally Posted by dsmith
Hello kai85. I am not sure of the official or school definition, but I can tell you the meaning that it has for me.

When you declare a variable, you have the option of allocating memory for that variable at compile time or at run time. For example, let's take an array. Suppose that you want work with 2-d matrices. So in your program, you would define:

CPP / C++ / C Code:
int matrix[100][100];

That would give you a 100x100 matrix of integers and it can not be changed unless you change your program and recompile it. This is known as compile time memory allocation. Right or wrong, I ussually refer to this as a static definition. Beyond, that it can't be changed, there is also some differences of how & where the memory is allocated and in addition it can not be "free'd" until the program is over.

Now, for the next example:
CPP / C++ / C Code:
int** matrix;

printf("How big would you like your matrix? ");
//get the number the using something like fgets & atoi
matrix = (int**) malloc( sizeof(int) * number * number);
This is run-time memory allocation. In C, you would use the malloc command and in C++ you would use the new command. Again, right or wrong, I call this dynamic memory allocation. I can make this any size I want, delete it, resize it, etc. all during program execution without recompiling. Thus it is run-time memory allocation.

There may be more to it than that, but that is my basic understanding.

HTH,
d

yea , thats what it thought too, just wanted to be sure.
thanks.
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simulation Problem wu_weidong C++ Forum 7 12-Mar-2005 22:56
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 15:13
Re: Programming Techniques WaltP C Programming Language 0 09-Mar-2004 23:56
time Problem zuzupus MySQL / PHP Forum 9 24-Jul-2003 07:02

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:17.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.