×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    151

    Arrow usage of CArrayFixFlat is correct or not

    Hello,

    struct FileInfo
    {
    TBuf<200> filename;
    TInt iVersion;
    TInt iInfoType;
    };

    struct FileList
    {
    TInt iTypeOfFile;
    CArrayFixFlat<FileInfo>* pFileInfoList;
    };

    CArrayFixFlat<FileList>* pFileList;

    first i read FileList struct from file.
    i store it in pFileList.

    pFileList->Append(ObjFileInfo);
    then i allocate memory for ObjFileInfo.pFileInfoList

    while deleteing i travers pFileList
    i delete pFileInfoList.

    then i delete pFileList.

    i didnt get any failure message.

    is it correct approch ?????????
    or there is anather way!

    Regards,
    Swapnil

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,699

    Re: usage of CArrayFixFlat is correct or not

    Although it is possible to handle such objects correctly, a more Symbian C++-ish approach would be
    Code:
    struct TFileInfo
    {
        TFileName filename;
        TInt iVersion;
        TInt iInfoType;
    };
    
    class CFileList : public CBase
    {
    public:
        TInt iTypeOfFile;
        RArray<FileInfo> iFileInfoList;
        ~CFileList() {iFileInfoList.Close();}
    };
    RArray is both faster and smaller than CArrayFixFlat, and you can not forget to initialize it, because it works without initialization too. However Close is necessary, and it produces more readable and object-oriented code if the object closes/deletes its member variables itself.
    TFileName is actually TBuf<255> (or 256?), and it is capable of storing any valid filename which can occur in a Symbian device (while TBuf<200> might turn out to be short in extreme situations).

    Because CFileList has become a C-object, it should be used via pointers, thus pointer arrays (CArrayPtrFix/Seg, or the faster-smaller RPointerArray) should be used to handle it:
    Code:
    RPointerArray<CFileList> filelist;
    ...
    filelist.ResetAndDestroy();
    Because pointer arrays "recognize" C-classes (in fact they recognize CBase - that is why we inherit from it), ResetAndDestroy will delete the CFileList objects (resulting in invocation of the destructor, thus Close-ing and freeing the contained array of TFileInfo)

  3. #3
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    151

    Re: usage of CArrayFixFlat is correct or not

    But the size of RArray is limited...........
    and whaterver i had written the clean up of CArrayFixFlat is corrct or not.

  4. #4
    Registered User
    Join Date
    Feb 2007
    Location
    Tampere
    Posts
    370

    Re: usage of CArrayFixFlat is correct or not

    Hi,

    Why do you think size of RArray is limited?
    Regards

    - MVP
    "Dare To Dream" - A.P.J.Kalam

  5. #5
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: usage of CArrayFixFlat is correct or not

    Quote Originally Posted by mrudulpen View Post
    Hi,

    Why do you think size of RArray is limited?
    There's a max size for each element, I can't remember how much something like 640 bytes, which however is more than the op's struct elelment.

  6. #6
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: usage of CArrayFixFlat is correct or not

    Quote Originally Posted by swapnil_mahajan View Post
    But the size of RArray is limited...........
    and whaterver i had written the clean up of CArrayFixFlat is corrct or not.
    You have an array of arrays, so if you traverse the 'outer' array and delete each 'inner' array in turn, then delete the outer array as you have described then yes it will work.

    However your code is what a C programmer would write, Symbian is C++, and has a philosophy and set of mechanisms and naming scheme to ensure correct cleanup.
    If you don't follow this scheme you will make things harder for yourself, and there is a high chance that your code will not interact with SYmbian C++ code in a cleanup-safe way. If you are using SYmbian C++ objects in C-like code you run this risk of this happening.

  7. #7
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    151

    Thumbs down Re: usage of CArrayFixFlat is correct or not

    Hi,

    am Creating instance of CFileList but it panics......

    CFileInfoList *pFileInfo;
    pFileInfo = NULL;
    pFileInfo = CFileInfoList::NewL();

    /// NewLC
    CFileInfoList*
    CFileInfoList::NewLC(
    )
    {

    CFileInfoList* self = new (ELeave) CFileInfoList();
    CleanupStack::PushL(self);

    return self;
    }

    /// NewL
    CFileInfoList*
    CFileInfoList::NewL(
    )
    {
    CFileInfoList* self = CFileInfoList::NewLC();
    CleanupStack::Pop(self);
    }
    Can you please tell me the reasons behind it.

    Regards,
    Swapnil

  8. #8
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: usage of CArrayFixFlat is correct or not

    "Can you please tell me the reasons behind it."

    If you tell us where it panics then we will do so.

  9. #9
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    151

    Re: usage of CArrayFixFlat is correct or not

    Quote Originally Posted by hotcheese View Post
    "Can you please tell me the reasons behind it."

    If you tell us where it panics then we will do so.
    Hi, I got the reason behind it.

    In TFileInfo i added 4 parameters so the size of the structure is greater than 640 bytes..

    Thanks for your help

    Regards,
    Swapnil

Similar Threads

  1. memory jump while running game
    By TacB0sS in forum Mobile Java Games
    Replies: 21
    Last Post: 2009-06-20, 11:56
  2. Voip Usage Battery Stats N95 8GB
    By rajil.s in forum VoIP
    Replies: 0
    Last Post: 2008-12-07, 18:55
  3. helping my symbian server take more CPU usage
    By loquendo in forum Symbian
    Replies: 3
    Last Post: 2008-11-24, 21:12
  4. Memory Usage more with S40 devices
    By muralidharvvk in forum Mobile Java General
    Replies: 6
    Last Post: 2008-06-03, 08:23
  5. Getting Ram usage of a process
    By Bernd42 in forum Symbian
    Replies: 0
    Last Post: 2004-02-17, 13:33

Posting Permissions

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