-
September 18th, 2010, 02:27 PM
#1
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
-
September 18th, 2010, 02:44 PM
#2
Re: Pointer question
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.
-
September 18th, 2010, 03:29 PM
#3
Re: Pointer question
Originally Posted by potatoCode
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|