How to instantiate class object NOT in the GC heap

Jonathan M Davis jmdavisProg at gmx.com
Sun Jul 15 12:43:49 PDT 2012


On Sunday, July 15, 2012 21:14:40 Benjamin Thaut wrote:
> Am 15.07.2012 21:06, schrieb Jonathan M Davis:
> > On Sunday, July 15, 2012 18:34:44 bearophile wrote:
> >> Alex Rønne Petersen:
> >>> This is how you do it in modern D:
> >> This seems fiddly and bug-prone (and eventually fit to go in the
> >> D FAQ).
> >> Maybe it needs to use an aligned_malloc, to avoid aligning
> >> troubles in the class.
> > 
> > It'll probably become easier to do once we have allocators, since it'll
> > probably become possible to do something like
> > 
> > auto alloc = getMallocAllator();
> > auto obj = alloc.make!T(args1, args2, args3);
> > 
> > - Jonathan M Davis
> 
> emplace has quite some issues especially when it can't find any
> constructor to call you have no clue whats happening. Here is my custom
> new which does quite some special case handling:

Well, if you have suggestions on how to improve emplace, then please create an 
enhancement request and/or a pull request. And with properly written custom 
allocators, all of the special casing should then be _in_ the allocator where 
you won't have to deal with it, making it so that you'd only really need 
emplace directly when you're doing something that none of the custom 
allocators will do (or you're writing your own custom allocator).

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list