我最近遇到过这种咆哮.
我不太明白文章中提到的一些要点:
deletevs 的小烦恼delete[],但似乎认为它实际上是必要的(对于编译器),而没有提供解决方案.我错过了什么?在"专业分配器"一节中,在功能中f(),似乎可以通过以下方式替换分配来解决问题:(省略对齐)
// 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<char> string(a); string.allocate(80);
// or: arena_ptr<char> string; string.allocate(a, 80);
arena_ptr<int> intp(a); intp.allocate();
// or: arena_ptr<int> intp; intp.allocate(a);
arena_ptr<foo> fp(a); fp.allocate();
// or: arena_ptr<foo>; fp.allocate(a);
// use templates …Run Code Online (Sandbox Code Playgroud)