|
-
December 1st, 2010, 12:14 PM
#12
Re: Tasteless mimic of operator new: Call ctor
 Originally Posted by Lindley
You seem to be thinking that the call to placement new is above the buffer allocation. I'm thinking it should be the other way around: your custom allocator decides if it has enough buffer space available, then calls placement new if so.
Yes, what an astute observation. Thank you.
I tried it that way a few times, but lost confidence because of the complexity of the solution details.
At first, I actually did make a global allocator for objects. But I really got lost in the implementation details. I believe that you need a lot of templates or tuples to do this because you need to support ctor calls with an unknown number of ctor input parameters. This would be a template with N+1 parameters, N ctor parameters plus one additional template type for the type of the class or struct. I wrote 10 individual templates for it, so as tu support ctors with up to 10 ctor params. And it worked just fine. I tried it with a few ctors with several parameters. Everything worked fine --- OK. But the implementation details were so ugly and crude, base and low, that I was ashamed of what I had done. So I switched it to the other way around --- on purpose. Placement new gets called, custom buffer allocates and may return 0.
Are you following this junk that I'm talking about? Or am I just totally on the wrong track?
Could you indicate any sensible way to create a global object allocator, I mean fully generic, to be used with placement new in combination with a custom buffer?
Sincerely, Chris.
You're gonna go blind staring into that box all day.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|