Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
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.
Old March 21st, 2009, 04:12 PM
Registered User
Join Date: Mar 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

Thanxs for your reply !
Old March 31st, 2009, 02:34 AM
Friend of Wrox
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289

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:

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;
    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..
1st code block

2nd code block

3rd code block

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

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.