Am 26.04.2011 23:49, schrieb Andrej Mitrovic: > On 4/26/11, Daniel Gibson <[email protected]> wrote: >> 2. you can even use different custom allocators for the same class at >> the same time (you'd have to be really careful not to screw that up by >> using the wrong deallocator for an Object) > > Maybe the allocator could annotate the class somehow, and the > deallocator could check which allocator was used to create the object > so it can call the matching deallocator. > > One way this could be done is through subclassing, but maybe that > would mess things up. And this would probably mean runtime checks as > well. I've never dealt with this before, but some ideas come to mind..
Yeah, just having one int/enum flag that indicates which allocator was used would be sufficient. However for that to work you have to use custom classes, that are all derived from MyObject or something like that (which is derived from Object and contains this flag). Depending on what you're doing this may not be a problem at all, but it's not as generic as being able to use *any* class. (Maybe?) Another possibility: the allocator returns a struct/class that contains this flag + the object and uses alias this to redirect everything to the contained class? I haven't really thought this through, but something like this could work. Cheers, - Daniel
