[Qt-interest] Replace Qt Allocator

Colin S. Miller no-spam-thank-you at csmiller.demon.co.uk
Wed Sep 16 19:15:05 CEST 2009


Dan White wrote:
> Short Answer: Don't use nedmalloc with C++
> 
> According to what appears to be the nedMalloc homepage <http://www.nedprod.com/programs/portable/nedmalloc/>, it is a variant on the old, classic C function "malloc"
> 
> This is dangerously bad
> Reference: <http://www.devx.com/tips/Tip/12491>
> 
> "Avoid Using malloc() and free() in C++
> The use of malloc() and free() functions in a C++ file is not recommended and is even dangerous: 
> 1. malloc() requires the exact number of bytes as an argument whereas new calculates the size of the allocated object automatically. By using new, silly mistakes such as the following are avoided: 
> 

Except that on some (most?) platforms there is code like this

void *operator ::new(size_type size)
{
    void *ret;
    ret=malloc(size);
    if (ret!=NULL)
      return ret;

    throw std::bad_alloc();
}



i.e.
::new() just calls malloc(), after being
told how much space it needs.

The C++ standard indicates that the malloc, new and new[] heaps
can be separate, (and the code must assume this), but they
can be the same if the library-writers wish.

HTH,
Colin S. Miller



More information about the Qt-interest-old mailing list