3 ms·
Really solid advice throughout. If you're using non-POD C++ and want to allow custom allocators (wise), I would keep it simple and use placement new instead of
by tomlu 13y ago
Really solid advice throughout.
If you're using non-POD C++ and want to allow custom allocators (wise), I would keep it simple and use placement new instead of messing about with per-class operator new. If you must you can wrap it up in little internal template functions to make it a little more palatable.
Eg:
template <typename T>
T *yl_new(Context *context) {
return new(context->malloc(sizeof(T)) T();
}
template <typename T>
void yl_delete(Context *context, T *object) {
object->~T();
context->free(object);
}
- the_mitsuhiko 13y agoThen you have to stop using STL containers altogether as those will just use operator new internally :(
- tomlu 13y agoTrue, but that has more to do with wanting to place the allocators on a context object. Even using custom allocators I don't think there's a way to supply a non-global context to the STL.