M
ManicQin
Heya everyone!
A Q for U...
I need to build an allocator for my objects, but! the trick is that:
* Allocator would manage his own MemAlloc And the MemFree (like dhu)
* One class could use a few types of allocators (meaning allocator is
not a static member of the class).
* I want the minimal overhead on a programmer, meaning that once he
attached an allocator to an object he wont need to remember what
allocator he attached (fire and forget)
* I could overload new and delete and use the allocator within them
One solution was makin the allocator a member of an object BUT new and
delete are defined as static functions and could only use a static
members. once i'll attach an allocator to an object all objects of the
type will use the same allocator... BAD (think what will happen if i
allocate an object with one allocator and free it with another)
Another solution was adding the allocator to the new and delete
operators, two major problems
1) i could live with specifing the allocator as an argument in the new
operator but, in the delete? two much overhead
2) the overloaded deltet doesnt work! i call it delete(new Allocator())
Object; and it redirects to the normal delete!
I think u got my drift ... its more of a design problem
I'll be happy to hear your thoughts
A Q for U...
I need to build an allocator for my objects, but! the trick is that:
* Allocator would manage his own MemAlloc And the MemFree (like dhu)
* One class could use a few types of allocators (meaning allocator is
not a static member of the class).
* I want the minimal overhead on a programmer, meaning that once he
attached an allocator to an object he wont need to remember what
allocator he attached (fire and forget)
* I could overload new and delete and use the allocator within them
One solution was makin the allocator a member of an object BUT new and
delete are defined as static functions and could only use a static
members. once i'll attach an allocator to an object all objects of the
type will use the same allocator... BAD (think what will happen if i
allocate an object with one allocator and free it with another)
Another solution was adding the allocator to the new and delete
operators, two major problems
1) i could live with specifing the allocator as an argument in the new
operator but, in the delete? two much overhead
2) the overloaded deltet doesnt work! i call it delete(new Allocator())
Object; and it redirects to the normal delete!
I think u got my drift ... its more of a design problem
I'll be happy to hear your thoughts