Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What memory is for the constants defined in a method?

Tags:

methods

c#

.net

Someone I could describe what happens (from the perspective of memory management) when a constant is defined within a method in. Net?

like image 978
Tom Sarduy Avatar asked Jun 12 '11 04:06

Tom Sarduy


People also ask

What are memory constants?

A constant is basically a named memory location in a program that holds a single value throughout the execution of that program. It can be of any data type- character, floating-point, string and double, integer, etc.

Where constants are stored in memory?

'const' variable is stored on stack. 'const' is a compiler directive in "C". The compiler throws error when it comes across a statement changing 'const' variable.

Do constants need memory?

A constant is a named memory location which temporarily stores data that remains the same throughout the execution of the program. The type of a variable indicates what kind of value it will store. The name of a variable is known as its identifier.

How constants are defined?

A constant is a value that cannot be altered by the program during normal execution, i.e., the value is constant. When associated with an identifier, a constant is said to be “named,” although the terms “constant” and “named constant” are often used interchangeably.


1 Answers

Constants are usually resolved at compile time and inserted into the instruction sequence directly. Example:

const int A = 10;
int b;

int i = A + b;

would effectively be compiled into:

int i = 10 + b;

For strings they are being interned and put on the heap.

like image 187
ChrisWue Avatar answered Sep 24 '22 18:09

ChrisWue