×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    34

    How to initialise elements of an array?

    Hello all

    Here I am trying to create an CArrayFixSeg array
    in .h file
    CArrayFixSeg<TInt> *iArray;
    in .cpp
    iArray = new(ELeave)CArrayFixSeg<TInt>(totalmembers);
    I want all the elements to be initialized to NULL. How can I do that?
    I tried the following but the program quits when it reaches that particular point.
    for (TInt j = 0; j < totalmembers; j++ )
    {
    iArray->At(j) = NULL; //here it quits
    }
    somebody please help.

    thanks in advance
    Deepak
    stay hungry, stay foolish :-)

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

    Re: How to initialise elements of an array?

    the totalmembers is granularity, i.e. defines for how many thingis the memory are reserved when adding stuff to teh array, it does not append anything into teh array, thus the array is empty in teh beginning.

    So, At() will fail since the number of elements in the array is zero.

    yucca

  3. #3
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: How to initialise elements of an array?

    Code:
    for (TInt j = 0; j < totalmembers; j++ )
    {
    iArray->AppendL(0); //here it quits
    }

  4. #4
    Registered User
    Join Date
    Jul 2007
    Posts
    34

    Re: How to initialise elements of an array?

    thanx for that express reply yucca and kumar. This worked.
    for (TInt j = 0; j < totalmembers; j++ )
    {
    iArray->AppendL(0);
    }
    thanks a lot.
    stay hungry, stay foolish :-)

  5. #5
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: How to initialise elements of an array?

    What it is that you are storing in there ?

    I usually have use CArrayFixFlat for ints, and RPointerArray for pointers.

    yucca

  6. #6
    Registered User
    Join Date
    Jul 2007
    Posts
    34

    Re: How to initialise elements of an array?

    Thanks for the tip yucca, i changed it to CArrayFixFlat. It is actually an array of integers only, to keep track of data assigning in another array.

    I have another problem, I have another CArrayFixSeg array of TBuf8<32> elements.
    iData = new(ELeave)CArrayFixSeg<TBuf8<32> >(totalmembers);
    here I am trying to assign data[text] to an arbitrary element in the array.

    iData->At(framenumber) = &ieData[6];//it quits here
    iArray->At(framenumber) = 1;
    The program quits when i try the above code
    Say, totalmembers = 10 and framenumber = 6, then will it fill the data from ieData[6] to the 7th element of the array?
    stay hungry, stay foolish :-)

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,683

    Re: How to initialise elements of an array?

    I guess it is the same problem again: "totalelements" passed for the constructor is still used as the granularity.
    Note that there is ResizeL of CArrayFix...-s, use it:
    Code:
    iData = new(ELeave)CArrayFixSeg<TBuf8<32> >(1);
    iData->ResizeL(totalmembers);
    CDesC8ArrayFlat/Seg also exists, however it has no ResizeL.

  8. #8
    Regular Contributor
    Join Date
    Mar 2007
    Location
    Brazil
    Posts
    103

    Re: How to initialise elements of an array?

    Isnt better to use Mem::FillZ() to zero-null all vallues of a array?

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,683

    Re: How to initialise elements of an array?

    Quote Originally Posted by cabezonxdg View Post
    Isnt better to use Mem::FillZ() to zero-null all vallues of a array?
    You can zero the elements, however you still have to make sure that there are elements. Consturctors of CArray...-s do not allocate memory for any elements. Also note that in case of segmented-array, using Mem::FillZ is far from being trivial.

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

    Re: How to initialise elements of an array?

    Quote Originally Posted by cabezonxdg View Post
    Isnt better to use Mem::FillZ() to zero-null all vallues of a array?
    People on this thread are thinking Symbian arrays are like C arrays i.e.
    int x[5]

    They're not.

Similar Threads

  1. Replies: 8
    Last Post: 2007-07-24, 05:04
  2. Replies: 1
    Last Post: 2007-04-05, 14:56
  3. Replies: 1
    Last Post: 2006-07-05, 18:05
  4. How to copy pointer to array?
    By chrishawaii in forum Symbian
    Replies: 10
    Last Post: 2006-06-06, 12:08
  5. Replies: 2
    Last Post: 2005-03-14, 15:22

Posting Permissions

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