[Interest] Internal Qt bug or incorrect user API call?

Bob Hood bhood2 at comcast.net
Thu Aug 28 13:31:19 CEST 2014

On 8/8/2014 5:46 PM, T Stutts wrote:
> Hi,
> This is a copy of my post
> at http://qt-project.org/forums/viewthread/46102/and I am taking the replied
> suggestion of asking the mailing list. I hope the copy/pasted markup is okay.
> What does this line
> <https://qt.gitorious.org/qt/digia-qt/source/705b0f958a6071341b10cbd51917e1378356491b:src/corelib/tools/qvarlengtharray.h#L194this> /[qt.gitorious.org
> <http://qt.gitorious.org>]/ line do?
> I am referring to the line
> 1.
>     new (ptr+(s++)) T(*abuf++);
> [...]
> It looks to me like an explicit memory leak (see new()
> <http://en.cppreference.com/w/cpp/language/new> /[en.cppreference.com
> <http://en.cppreference.com>]/). 
> It expressly allocates dynamic memory and does not store the pointer
> anywhere, unless Qt has its own allocation implementation
> (ie set_new_handler()
> <http://en.cppreference.com/w/cpp/memory/new/set_new_handler>/[en.cppreference.com
> <http://en.cppreference.com>]/).

I've not looked at the code, but that does seem to be a non-standard use of
the keyword.  So it could be a custom "new" that Qt uses, or -- I've never
seen it used before -- it might be the "placement" form of the C++ new

    placement (3)

    void* operator new (std::size_t size, void* ptr) throw();

    Simply returns ptr(no storage is allocated).
    Notice though that, if the function is called by a /new-expression/, the
    proper initialization will be performed (for class objects, this includes
    calling its default constructor).

Just guessing.  :)

[1] http://www.cplusplus.com/reference/new/operator%20new/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140828/cdaa59b6/attachment.html>

More information about the Interest mailing list