×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Nov 2006
    Location
    Chengdu China
    Posts
    169

    <Need for comments> - 02

    TBuf(C) & HBufC
    TBuf is meant to be used on stack or within the data section of another object. It doesn` t need a destructor the same as any other T classes. However, we still can write code like this:
    TBuf<1>* buf = new (ELeave) TBuf<1>();
    actually, we can allocate memory for any T class on heap. a quick fix to this is to overload operator new as private

    HBufC faces the same problem, though it s 100% sure that any HBufC object is on heap, because the constructor is defined as private and several static function are provided to return the pointer of a new object, but we can still try something bad
    HBufC buf = *HBufC::NewL(1);
    and what s worse is that we can not write delete &buf.
    To make sure HBufC is on heap, and we can` t write code above, we need to declare destructor as private also, and add another public function to release the HBufC object
    The dream is to become one machine, or let one machine become me

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

    Re: <Need for comments> - 02

    And the point on this academic sounding wonderings is ?

  3. #3
    Regular Contributor
    Join Date
    Nov 2006
    Location
    Chengdu China
    Posts
    169

    Re: <Need for comments> - 02

    Just wondering if T is really a T, can it be something else rather than T, and is there anything we can do to make it more T.
    Don` t have a point, actually.
    The dream is to become one machine, or let one machine become me

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

    Re: <Need for comments> - 02

    I would think that basically you can not expect on how people would use things, and thir always finf ways on doing it wrongly anyway..

    -we all are 138-

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,697

    Re: <Need for comments> - 02

    You can not really stop people from producing low-quality code. And also remember that T is just a naming convention, from the C++ point of view there is nothing wrong with allocating T-type variables on the heap, just it rarely makes sense in Symbian C++.

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

    Re: <Need for comments> - 02

    You've picked two out of 10000 possible bad things a coder will do.

    Stupid and bad coders are stupid and bad whether they are using SYmbian C++ or C++ or Java or Cobol or whatever.

    There are tens of thousands of programmers, actually doing it for a job and getting paid for it, many of them on this site, when they should pack it in and find another job because they are not and never will be developers even if thats what their job title says.

    Some of the badness is due to ignorance some due to them being imbiciles.

    You cannot put things in place to stop stupid coders doing things if that will prevent a non stupid coder from doing something if there is a legitimate reason.

    TBuf (or T objects in general) should not have a mechanism to prevent people from allocating them on the heap. There will be occassions when it is necessary to do so, you should not stop people who know what they are doing from being able to do something if the reason is to protect the stupid.

    In fact, does it actually state categorically anywhere that T objects must not go on the heap? Should not is not the same thing as must not.


    P.S.
    HBufC buf = *HBufC::NewL(1);
    DOes this compile?

    P.P.S
    The nature of T objects, in relation to destructors etc. has actually changed now. Check out the latest documentation on the Symbian Foundation.
    Last edited by hotcheese; 2009-07-03 at 20:47.

Similar Threads

  1. retrieving MMS with WSP Get??!!!
    By nicoleta in forum General Messaging
    Replies: 8
    Last Post: 2010-12-09, 21:03
  2. Resolverplugin replies message 401
    By dimaar in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2008-12-10, 17:09
  3. WIMA 2008 - Nokia Forum NFC Developer Training
    By geri-m in forum Near Field Communication
    Replies: 3
    Last Post: 2008-05-13, 09:45
  4. Replies: 1
    Last Post: 2002-12-16, 12: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
  •  
×