Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

big number wasting memory?

Status
Not open for further replies.

ajikoe

Programmer
Apr 16, 2004
71
ID
Hello,

I would like to use a lot of process which will use big numbers variable such as :
double.MaxValue
int.MaxValue
Is it will waste my memory when I do the process?
For simple example :
public class test{
int i;
public test(int inpI){
i = int.MaxValue - inpI
}
.....
.....
}
Sincerely Yours,
Pujo
 
A double takes the same amount of memory, no matter what the contents. You can use the sizeof operator to see this for any value type.

That being said, you have to make sure the contents stay within the range that the variable supports (between MinValue and MaxValue, plus the special values of NegativeInfinity and PositiveInfinity for double).

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
It isn't really how much memory a double occupies that's the issue here, more a case of how many of them you want to have resident in memory at the same time.

You say you would like 'a lot'. What's that? Hundreds? Thousands? Millions?

Memory usage is only really a problem when you don't have enough for what you want to do. Otherwise, if it's there, you may as well use it.
 
I would like to add to the previous posts the you should use checked when you do calculation and conversions in order to get overflow exceptions.
Example:
Code:
int x = 1000000;
int y = 1000000;
int z=x*y; // z is -727379968 !!!
The program is working with wrong z but with the following code:
Code:
int x = 1000000;
int y = 1000000;
int z=checked(x*y);
the Overflow exception is thrown.
obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top