Pointer question
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Pointer question

  1. #1
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Pointer question

    I have a reference counting class in my personal library and while I was 'refactoring' it, I ran into a problem.

    My question is that how can I tell apart a pointer returned by new from that of new []?

    My understanding is that the compiler (at least GCC) has no way of knowing the allocator used, nor it is specified by the Standard. The deeper I get down to memory managment, the bitter I feel about operator new/delete, let alone the frustration I felt with std::allocator

    Or maybe, I'm not thinking straight...

    Does anyone know how?
    Thanks.
    Last edited by potatoCode; September 18th, 2010 at 02:34 PM. Reason: changed the statement

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,196

    Re: Pointer question

    Quote Originally Posted by potatoCode
    My question is that how can I tell apart a pointer returned by new from that of new []?
    If the reason you want to know this is to that you can use delete or delete[] appropriately, then one possible solution is to allow a custom deleter, like std::tr1::shared_ptr.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    May 2009
    Posts
    2,413

    Re: Pointer question

    Quote Originally Posted by potatoCode View Post
    I have a reference counting class in my personal library
    Reinventing the wheel is not only a waste of time, it usually ends with a flat tire.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center