Type information not passed with new/malloc, only size_t
<p><strong>EDITED: reworded question.</strong></p>

<p>When new and malloc are called, the size of the block of memory to be allocated is passed:</p>

<pre><code>void* malloc(size_t);
void* operator new(size_t);
</code></pre>

<p>is it possible to get type information, i.e. so you could do a sizeof(T) where T was the type the memory was being allocated for:</p>

<pre><code>T t = new T;
</code></pre>

<p>I'd like to overload new and malloc but require the type information not just the size of the memory being allocated.</p>

<p><strong>FURTHER EDIT:</strong></p>

<p>The reason I am doing this is that I will overload malloc. This function will inspect the size of the memory being allocated and allocate from a particualr memory pool:</p>

<pre><code>        template &lt;int v&gt; struct int2type { value = v };

        inline void* malloc(const std::size_t sz)
        {
            if(sz &lt;= 64)
            {
                size_obj* ptr = malloc(nggt::core::int2type&lt;sizeof(size_obj) + (sz % 8)&gt;);
                ptr-&gt;sz = sz;
                return ptr+1;
            }
            else if(sz &lt;= 128)
            {
                size_obj* ptr = malloc(nggt::core::int2type&lt;sizeof(size_obj) + 128&gt;);
                ptr-&gt;sz = sz;
                return ptr+1;
            }
            else
            {
                return TSuper::malloc(sz);
            }
        }


        inline void* malloc(const nggt::core::int2type&lt;sizeof(size_obj) + 8&gt; sz)
        {
            return m_heap8.malloc(sz.value);
        }

        inline void* malloc(const nggt::core::int2type&lt;sizeof(size_obj) + 16&gt; sz)
        {
            return m_heap16.malloc(sz.value);
        }
</code></pre>

<p>There are also supporintg free overloads using a freelist to return memory to a pool. Problem is I can't use <code>size_t sz</code> in a template as it's not known at compile time. If I could get the type information I could do <code>sizeof(T)</code> and be done!</p>

<p>Cheers,
Graeme</p>
