Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 21st, 2009, 04:09 PM
Registered User
 
Join Date: Mar 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question Difference b/w int i; and myClass objmyClass

I want to know difference between int i; and myClass objmyClass; in terms of memory allocation.
  #2 (permalink)  
Old March 21st, 2009, 04:12 PM
Registered User
 
Join Date: Mar 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanxs for your reply !
  #3 (permalink)  
Old March 31st, 2009, 02:34 AM
Friend of Wrox
 
Join Date: Mar 2008
Location: So Cal is good enough for you, California, USA.
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

its been a while since i read this. but if your asking how much space each one takes up, it varies depending on how big that class is. ints take up 4 bytes or something like that. as far as that class you were asking about, you need to add the size of each member and that will be its total size in bytes. i find it much easier to use the sizeof() function (its in c++ but i dont know about C#... never really cared haha).

here is some code:

Code:
 
struct EmployeeRecord {
      int ID;
      int age;
      double salary;
    };
int main()
{
    cout << "sizeof(int): " << sizeof(int) << endl
         << "sizeof(float): " << sizeof(float) << endl
         << "sizeof(double): " << sizeof(double) << endl
         << "sizeof(char): " << sizeof(char) << endl
         << "sizeof(EmployeeRecord): " << sizeof(EmployeeRecord) << endl;
    
    system("PAUSE");
    return 0;
}
here it will say int's are 4 bytes each in size, float is 4, double is 8 and char is 1. also the EmployeeRecord is 16 bytes (the sum of all its members). If you want to know more about how it actually gets stored in memory, i'd suggest an asm tutorial. its one of the first few things they talk about. You will learn about segments and offsets. Its nothing we really need to concern ourselves with but knowledge is never wasted.

Testing 1..2.. 3..
Code:
1st code block
Code:
2nd code block
Code:
3rd code block
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading An int Doom C# 1 January 7th, 2008 01:43 PM
Difference bet Convert.Toint32 and Int.Parse anujrathi General .NET 3 September 8th, 2007 02:31 AM
int? asn187 C# 2 March 30th, 2007 06:05 AM
What's the difference between an int and a long jnrico C++ Programming 4 March 4th, 2007 01:29 AM
file or assembly name "myClass", or one of its dep transtar BOOK: ASP.NET Website Programming Problem-Design-Solution 3 April 12th, 2005 10:39 AM



All times are GMT -4. The time now is 02:27 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.