reducing memory usage
<p>i am developing a project in which i have used many classes.
for creating classes i have used the new operator...example, in banana class i have an instance variable of class apples......</p>

<p><strong>THIS IS A SCALED DOWN REPRESENTATION OF WHAT I WANT TO SAY &amp; DOES NOT REPRESENT THE CODE WORD-TO-WORD...SO PLEASE DO NOT POINT AT SYNTAX ERRORS...BUT TRY TO UNDERSTAND THE METHODOLOGY</strong></p>

<p>in header file (banana.h):</p>

<pre><code>static int counter = 0;
class banana
{
  public:
  apples *ap_obj;//(apple is a class defined another file apples.cpp)
  int *index;
}
</code></pre>

<p>in banana.cpp :</p>

<pre><code>class banana
{
  banana::banana(void)
  {
    ap_obj = new apples;
    index = new int;
    *index = ++counter;
  }
};
</code></pre>

<p>my first question is that, is my method correct in terms of memory efficiency?
( i know that i dont have any run time error for sure)</p>

<p>my second question is that, i want to access a banana object in 1 of my methods of any class by using the index (plz note that every banana object has a unique index) variable.
for this i am thinking of using another class registry(because i want to store indexes of many classes's objects).
i am thinking of storing the pointer of 1st object of any class in my registry class.
&amp; for accessing the pointer of any nth object of a class, i plan to use pointer arithmatics on the 1st object using the index variable...example</p>

<pre><code>class registry
{
  banana *base_obj;//this value will be initialised when i create the 1st object of banana class
  banana *registry::get_nth_object(int shift);
  {
    return *(base_obj + shift);//shift is the index variable of banana class
  }
};
</code></pre>

<p>in any other class i can just call <strong>get_nth_object</strong> &amp; pass the index no of the object whose pointer i want &amp; i will get that point.</p>

<p>is there anything wrong in my code?
or if anything can be improved please help me.</p>

<p>for refernce i use <a href="http://www.cplusplus.com" rel="nofollow">http://www.cplusplus.com</a>.
i am a mech engg student so please pardon me if i have made any stupid mistake</p>
