×

Discussion Board

Results 1 to 14 of 14

Thread: CBase issue

  1. #1
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    68

    CBase issue

    Hi,

    Symbian documentaion says CBase class will zero initialize all member variables.
    But this doesn't seem to happen so for simple heap based classe derived from CBase

    any comments?

    regards
    arun

  2. #2
    Registered User
    Join Date
    Apr 2005
    Location
    Barcelona
    Posts
    1,678

    Re: CBase issue

    Please show us a snippet of your code.

    (CBase's operator new will zero out the object btw)

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

    Re: CBase issue

    >any comments?

    Yes, your code isn't following convention somehow.

  4. #4
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    68

    Re: CBase issue

    Hi,

    I have the following class (some data and function removed to make it small)

    class CTodoChangesDBublic CBase
    {
    public:
    public:
    //construction and destruction
    ~CTodoChangesDB();
    static CTodoChangesDB* NewL();

    /*
    Used by ui to open/close the db when starts
    Trap as they can leave
    */
    TInt CreateDBL(const TFileName& aNewChangesDBFile);
    TInt OpenDBL(const TFileName& aNewChangesDBFile);
    void Close();

    private:
    CTodoChangesDB();
    void ConstructL();
    TInt CreateTables();
    void CreateChangesTableL();
    void CreateUploadTableL();
    void CreateCountTableL();
    void DropChangesTable();
    TInt InitVariables();
    TInt InitializeTablesL();
    private:
    TBool iTempRefreshNeeded;
    TBool iRefreshNeeded;

    //to store the last sync type, manual or shcduled
    // starts with schdule and changes for each of the syncs
    TInt32 iLastSyncType;
    TInt32 iSyncStatus;
    //used to keep track of the record we are sending
    TInt32 iRecordCount;
    TInt32 iTotalRecords;
    // Store data

    RFs iFsSession; /* For use of iFileStore */
    RDbStoreDatabase iChangesDB;/* For database operations */
    CFileStore* iFileStore; /* For creating and opening database files */
    TBool iOpen; /* Flag indicating iChangesDB open status*/

    };

    I could see that none of the data variables were zero initialized and i was forced to so.

    regards
    arun

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

    Re: CBase issue

    But you haven't shown how you create the object.
    Last edited by hotcheese; 2007-10-25 at 14:20.

  6. #6
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: CBase issue

    Its working as designed - as PushL says, operator new does the zeroing, not the constructor.

  7. #7
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    68

    Re: CBase issue

    Hi,
    I use the two phase construction method and there is new (Eleave) used for creation of the class.

    But the members are never initialized to zero.

    what could be the issue?

    regards
    arun

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,752

    Re: CBase issue

    Actually you can check it for yourself: all "operator new()"-s of CBase are inline-d, and you can find their implementation in e32base.inl. They use User::AllocZ and User::AllocZL or Mem::FillZ in the special case when you supply the base address.
    If your class does not get zero-ed on new(ELeave), it likely does not inherit from CBase.

  9. #9
    Super Contributor
    Join Date
    Jul 2006
    Location
    Oulu, Finland.
    Posts
    1,174

    Re: CBase issue

    Can you tell us, how do you check that your members are not zero initialized?

  10. #10
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    68

    Re: CBase issue

    Hi,

    The class is derived from CBase (i had put the code already in the thread).

    class CTodoHandler: public CBase
    {
    public:
    static CTodoHandler* NewL();
    private:
    CTodoHandler();
    public:
    TInt i;
    HBufC* ptr;
    };

    when i call CToHoHandler* temp = new (ELeave) CTodoHandler() inside the NewL() function i am expecting the values of i and ptr to be 0.

    But this is not happening at all for me.
    regards
    arun

  11. #11
    Super Contributor
    Join Date
    Mar 2004
    Location
    Czech Republic
    Posts
    2,037

    Re: CBase issue

    Hi arunpirku,

    are you really sure, beacuse it looks really strange - as others said the AllocZ() is used when "symbian" operator new(TUint aSize, TLeave) is used - it allocates the object from the heap and then initialises its contents to binary zeroes... No idea what could go wrong...

    BR
    STeN

  12. #12
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    68

    Re: CBase issue

    Hi all,

    I have many classes where this issue is there.
    For example:
    i had to initialize all members to 0 or NULL, (here is it a constructor with an argument).
    CTodoHandler* temp = new (ELeave)CTodoHandler(aAppUi);

    Fo a no argument constructor too, i had to initialze the members to 0.
    CTodoChangesDB* tmp = new (ELeave)CTodoChangesDB();


    regards
    arun

  13. #13
    Regular Contributor
    Join Date
    Mar 2006
    Posts
    280

    Re: CBase issue

    Could you be using a different new operator?
    Do you link to any unusual libs?
    Is it the same in the debug and release builds?
    What values does the memory hold? (is it random, or somehting like DEDE?)
    Are you sure you are running the code you think you are? Could you be running very old code and just not notice that the build has failed?
    Is your constructor empty?

  14. #14
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,752

    Re: CBase issue

    Actually it is also possible to "Step Into" the ...=new(ELeave) line, at least in CodeWarrior. Then the cursor jumps to e32base.inl in my case. You can check what happens in your code.

Similar Threads

  1. issue with at+cusd over bluetooth link
    By hbanks in forum General Messaging
    Replies: 2
    Last Post: 2007-09-25, 21:21
  2. RTSP video streaming issue on 6280
    By olivier_irac in forum General Development Questions
    Replies: 0
    Last Post: 2006-12-04, 15:11
  3. Image Scaling/Sizing issue on the N70
    By sameet in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2006-07-24, 12:03
  4. Problem with inheritance (CBase)
    By julppoupou in forum Symbian
    Replies: 2
    Last Post: 2005-08-01, 07:45

Posting Permissions

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