×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    339

    how to reuse RPointerArray ?

    hi , I have an array of objects derived from CBase class. I used RPointerArray to hold objects. In some state of the application i need to empty the contents of the array and reuse it. my approach is whenever i need to free contents of array i called FreeArray().


    Code:
    
    RPointerArray<CTest> iTestArr;
    
    
    void FreeArray()
    {
    
    	for(TInt i=0; i<iTestArr.Count; i++)
    	{
    	delete iTestArr[i];
    	iTestArr.Remove(i);
    	}
    
            iTestArr.Reset();
    
    }

    Can I use ResetAndDestroy() of RPointerArray here instead of FreeArray() ? Thanks.

  2. #2
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,143

    Re: how to reuse RPointerArray ?

    ResetAndDestroy() should be fine, thus what kind of problems have you experienced with it ?

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    339

    Re: how to reuse RPointerArray ?

    Quote Originally Posted by symbianyucca View Post
    ResetAndDestroy() should be fine, thus what kind of problems have you experienced with it ?
    thanks symbianyucca for your reply. Actaully doing some refactoring, so just to know whether it could be used here, as I need to reuse RPointerArray object.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,570

    Re: how to reuse RPointerArray ?

    ResetAndDestroy is an inline method, you can find it in e32base.inl of any SDK:
    Code:
    template <class T>
    void CArrayPtr<T>::ResetAndDestroy()
    /**
    <comment part removed>
    */
    	{
    	for (TInt i=0;i<this->Count();++i)
    		delete this->At(i);
    	this->Reset();
    	}
    EDIT: note that your code is actually bogus: Remove shifts the entire array, which results in emptying half of the array only at the end (objects at even indices of the original array are removed). Also, re-organizing the array after every step requires some effort too.
    Now as I see, Count is not a method call either, so I guess the snippet is probably more of a pseudo-code than a real one.
    Last edited by wizard_hu_; 2012-01-12 at 12:04.

  5. #5
    Registered User
    Join Date
    Dec 2009
    Posts
    339

    Re: how to reuse RPointerArray ?

    thanks wizard_hu_. So using ResetAndDestroy() here is the better option or could you give me any other option in such case?
    Last edited by slinx; 2012-01-12 at 12:14.

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,570

    Re: how to reuse RPointerArray ?

    ResetAndDestroy is just fine, you can use it and it will work. There is no better alternative, it does the absolutely necessary steps.

Similar Threads

  1. reuse inputstream
    By asifsanli in forum Mobile Java General
    Replies: 3
    Last Post: 2011-05-06, 20:23
  2. How to reuse TPtr8
    By carlyle in forum Symbian
    Replies: 1
    Last Post: 2009-09-01, 09:34
  3. reuse of a socket
    By atahiana in forum Symbian
    Replies: 3
    Last Post: 2008-08-27, 15:33
  4. Reuse of timers
    By 76Richard76 in forum Symbian
    Replies: 5
    Last Post: 2008-04-21, 14:02
  5. reuse audio files
    By Rozik in forum Mobile Java General
    Replies: 2
    Last Post: 2007-11-14, 07:40

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •