For Programmers: Free Programming Magazines  


Home > Archive > VC Language > January 2006 > Re: Overloading new









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Overloading new
maynard

2006-01-24, 7:07 pm

>
> Have you seen what 'sz' is before you scale it down?
>
>

Yes...sz is the size in bytes needed for allocation (before I scale it
down).

> I am not sure why but you actually lose a chunk of your array here.
>
>

I was following a technique I found here:
http://www.icce.rug.nl/documents/cplusplus/
(in section 9.9.1).

>
> The system calls "new operator" that figures out the size (your 'sz') and
> then calls "operator new[]", after which it takes the returned pointer and
> apparently adjusts it. You're not supposed to fiddle with the array
> before "new operator" gives it back to your 'myObj'.
>

If this is the case, then I'm going to have to try something else. In
reality, although I didn't show it in my example, I'm deriving from
another class (written by somebody else) that only allows
initialization through overloaded constructors (bad, bad, bad!). Of
course, this doesn't work if you try and declare an array of these
objects. I may have to implement a simple allocation method
instead...I was just trying to implement a "quick fix" and something
clean to use, that's all.

As usual, thanks for your help V!

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com