Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-29-2007, 01:02 PM
Senior Member
 
Join Date: Nov 2007
Posts: 111
bugger is on a distinguished road
Object creation and memory issues
Code:
ClassName obj; // line no 1 obj = new ClassName(); // line no 2 obj.attributeName = "abc";
I want to know, when memory for object named obj is reserved? Lets assume that ClassName has 2 attributes but in the example above, we set only one attribute. Does this mean that there is not memory reserved for the second attribute of obj?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-29-2007, 01:48 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
As far as I know, when you set the attribute values, system wont reserved the memory.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-29-2007, 01:55 PM
Senior Member
 
Join Date: Nov 2007
Posts: 111
bugger is on a distinguished road
I am not getting you. You mean memory is not reserved at creating time and is set at runtime?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-29-2007, 02:10 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Sorry for the miss-representation.

yep at the runtime it is happened.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-29-2007, 02:19 PM
Senior Member
 
Join Date: Nov 2007
Posts: 111
bugger is on a distinguished road
Ok thanks... So even if my class had 10 attributes and an object is using just one, no space will be reserved for the remaining 9.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-29-2007, 02:24 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Never, until you assign values and use it.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 11-29-2007, 02:26 PM
Senior Member
 
Join Date: Nov 2007
Posts: 111
bugger is on a distinguished road
Okey. I have an object and want to know how much memory it is using in terms of bytes.

I know it is possible in C/C++. Can we do this in Java?
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 11-29-2007, 02:32 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Read this page.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 11-29-2007, 02:49 PM
Senior Member
 
Join Date: Nov 2007
Posts: 111
bugger is on a distinguished road
Great article. So one can use the following to know the memory allocations.

Code:
Runtime.freeMemory() Runtime.maxMemory() Runtime.totalMemory()
And there is no sizeOf() method in Java.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 11-29-2007, 02:51 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
yep. There is no sizeOf() like in C++. In Java it is so easy actually, and I don't know how to do it in C++.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 11-29-2007, 02:55 PM
Senior Member
 
Join Date: Nov 2007
Posts: 111
bugger is on a distinguished road
I like it in C++ Its simple there
In Java, you have to calculate the memory consumption after creating each object while in C++, you just call a method and get the memory consumed.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 11-29-2007, 02:56 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Let see if I got a chance to work with C++. May you help need for me.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java performance Issues (II) - Memory JavaForums Java Blogs 0 01-30-2008 03:01 PM
removing an object from memory ravian New To Java 1 11-12-2007 11:23 PM
Java Applet re-creation problem Mikalai.Kardash Java Applets 0 07-23-2007 04:09 PM
creation of new function an8086 Advanced Java 1 07-16-2007 04:20 PM
creation of new folder in the mail an8086 Advanced Java 1 07-15-2007 07:10 PM


All times are GMT +3. The time now is 03:23 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org