|
|
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.
|
|

11-29-2007, 01:02 PM
|
|
Senior Member
|
|
Join Date: Nov 2007
Posts: 111
|
|
|
Object creation and memory issues
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?
|
|

11-29-2007, 01:48 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
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.
|
|

11-29-2007, 01:55 PM
|
|
Senior Member
|
|
Join Date: Nov 2007
Posts: 111
|
|
|
I am not getting you. You mean memory is not reserved at creating time and is set at runtime?
|
|

11-29-2007, 02:10 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
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.
|
|

11-29-2007, 02:19 PM
|
|
Senior Member
|
|
Join Date: Nov 2007
Posts: 111
|
|
|
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.
|
|

11-29-2007, 02:24 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
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.
|
|

11-29-2007, 02:26 PM
|
|
Senior Member
|
|
Join Date: Nov 2007
Posts: 111
|
|
|
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?
|
|

11-29-2007, 02:32 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
__________________
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.
|
|

11-29-2007, 02:49 PM
|
|
Senior Member
|
|
Join Date: Nov 2007
Posts: 111
|
|
Great article. So one can use the following to know the memory allocations.
Runtime.freeMemory()
Runtime.maxMemory()
Runtime.totalMemory()
And there is no sizeOf() method in Java.
|
|

11-29-2007, 02:51 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
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.
|
|

11-29-2007, 02:55 PM
|
|
Senior Member
|
|
Join Date: Nov 2007
Posts: 111
|
|
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.
|
|

11-29-2007, 02:56 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
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.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|