Creating C++ Objects
I have seen two ways that objects can be declared from classes. Say the class name is CObject.
One way is the standered way which i use:
CObject Obj1;
And the other is to use the new keyword:
CObject *Obj1 = new CObject
In a previous post I heard it said that the only diffrance is that when a object is instantiated with the new keyword it is allocated on the heap. What differance does this make and why would you want to instantiate an object on the heap? Are there any speed benefits? The only reason I could see for wanting to use the new keyword is if you wanted to declare an dynamic array of objects of type CObject
Thanks Alot :-)
Cause the heap is BIG =)
Say you were creating a huge array of objects, or if you objects required a lot of space, or both...you''d want to create them on the heap and avoid the limited stack memory. Also, with new you can create linked lists of objects and other data structures.
I won''t go too deep into it, sounds like you got the info and just wanted clarification, plus, this post will bring out a million text book responses.
R!
Say you were creating a huge array of objects, or if you objects required a lot of space, or both...you''d want to create them on the heap and avoid the limited stack memory. Also, with new you can create linked lists of objects and other data structures.
I won''t go too deep into it, sounds like you got the info and just wanted clarification, plus, this post will bring out a million text book responses.
R!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement