Note that there are some explanatory texts on larger screens.

plurals
  1. POworst that can happen if i don't obey the stateless custom allocators dogma?
    primarykey
    data
    text
    <p>I need to create a custom allocator for std:: objects (particularly and initially for std::vector) but it might eventually come to use others</p> <p>The reason I need to create a custom allocator is that I need to track allocated (heap &amp; stack) resources by individual components of the application (<em>this is an inherent feature of the application</em>). I will need the custom allocator to monitor the heap portion of the resources, so it is essential that I'm able to pass to the std::vector constructor something like</p> <pre><code>trackerId idToTrackUsage; myAlloca&lt;int&gt; allocator(idToTrackUsage); vector&lt;int&gt; Foo( allocator ); </code></pre> <p>However, after reading a bit I found this little bomb about the STL / C++ standard (see references) saying that all allocator instances of a given type should be equivalent (that is that == should return true for any two instances) and, most terminal; any allocator should be able to deallocate memory allocated by any other instance (that is, without having a way to know what that other instance might be). In short, allocators cannot have state.</p> <p>So I'm trying to find the best way around this. Any clever ideas? I really really REALLY don't want to have to keep a custom version of std::vector around.</p> <p>EDIT: i read about scoped allocators for c++0x on <a href="http://www2.research.att.com/~bs/C++0xFAQ.html#scoped-allocator" rel="noreferrer">http://www2.research.att.com/~bs/C++0xFAQ.html#scoped-allocator</a> but i couldn't really get far into understanding how this applies to my problem. If anyone thinks c++0x alleviates this problem, please comment</p> <p>References:</p> <p><a href="http://en.wikipedia.org/wiki/Allocator_(C%2B%2B)" rel="noreferrer">Allocator C++ article in Wikipedia</a></p> <p><a href="http://www.codeguru.com/Cpp/Cpp/cpp_mfc/stl/article.php/c4079/" rel="noreferrer">Some random further reading courtesy of Google</a></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