Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues with C++ 'new' operator?
    primarykey
    data
    text
    <p>I've recently come across <a href="http://www.scs.stanford.edu/~dm/home/papers/c++-new.html" rel="nofollow noreferrer">this rant</a>.</p> <p>I don't quite understand a few of the points mentioned in the article:</p> <ul> <li>The author mentions the small annoyance of <code>delete</code> vs <code>delete[]</code>, but seems to argue that it is actually necessary (for the compiler), without ever offering a solution. Did I miss something?</li> <li><p>In the section 'Specialized allocators', in function <code>f()</code>, it seems the problems can be solved with replacing the allocations with: (omitting alignment)</p> <pre><code>// if you're going to the trouble to implement an entire Arena for memory, // making an arena_ptr won't be much work. basically the same as an auto_ptr, // except that it knows which arena to deallocate from when destructed. arena_ptr&lt;char&gt; string(a); string.allocate(80); // or: arena_ptr&lt;char&gt; string; string.allocate(a, 80); arena_ptr&lt;int&gt; intp(a); intp.allocate(); // or: arena_ptr&lt;int&gt; intp; intp.allocate(a); arena_ptr&lt;foo&gt; fp(a); fp.allocate(); // or: arena_ptr&lt;foo&gt;; fp.allocate(a); // use templates in 'arena.allocate(...)' to determine that foo has // a constructor which needs to be called. do something similar // for destructors in '~arena_ptr()'. </code></pre></li> <li><p>In 'Dangers of overloading ::operator new[]', the author tries to do a <code>new(p) obj[10]</code>. Why not this instead (far less ambiguous):</p> <pre><code>obj *p = (obj *)special_malloc(sizeof(obj[10])); for(int i = 0; i &lt; 10; ++i, ++p) new(p) obj; </code></pre></li> <li><p>'Debugging memory allocation in C++'. Can't argue here.</p></li> </ul> <p>The entire article seems to revolve around classes with <em>significant</em> <em>constructors</em> and <em>destructors</em> located in a <em>custom memory management scheme</em>. While that could be useful, and I can't argue with it, it's pretty limited in commonality.</p> <p>Basically, we have placement new and per-class allocators -- what problems can't be solved with these approaches?</p> <p>Also, in case I'm just thick-skulled and crazy, in <strong>your</strong> ideal C++, what would replace <code>operator new</code>? Invent syntax as necessary -- what would be <strong>ideal</strong>, simply to help me understand these problems better.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload