Re: Memory issues.

Dennis <[email protected]>
Newsgroups gmane.games.devel.mud.rom
Message-ID <[email protected]>
"const" has nothing to do with memory allocation.
Memory is allocated the same whether a variable is marked const or not.

Marking a variable as constant simply tells the compiler 
"This variable should not be modified".

Here are a few benefits to using "const":
- It helps to catch programming mistakes.
 	The compiler will spit an error at you if you try to modify a
 	variable that's not supposed to change.

- It tells other programmers the variable won't be changed.  For example:

 		void func1 ( char * txt );

 	You don't know what this function does.  It might go through and change
 	the string you send to it.

 		void func1 ( const char * txt );

 	However, you know that this function will not touch the string you send.

-  The compiler may be able to optimize the compiled code
 	if it knows that some variables are never going to change value.

 	(It is possible that using "const" could produce slightly
 	faster code.  It should NEVER produce slower code).


On Thu, 7 Apr 2005, Valnir wrote:

> Well... I have to admit.. I have modified send_to_char to NOT have a "const" 
> in it.. it's a standard "char" now. It seems to have become much more 
> efficient now. The fact that it was a const was a little stupid in my book. 
> If I'm wrong, please tell me, and explain to me why. From what I understand, 
> a const is allocated and never released so it can be used in other functions 
> without having to be passed directly to the other function.. now it I'm 
> sending the "txt" to the other function in the function arguments, why in the 
> hell should it be a const?
>
> - Valnir
-- 
ROM mailing list
[email protected]
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.