Re:Why is Zig so Cool?
by bnolsen on Monday November 10, 2025 @09:33PM
(#45883528)
Custom allocators in c++ was never enjoyable nor easy. It introduces more template slop everywhere. That's one thing I really liked about eastl, it did allocators much better. But it wasn't maintained.
[ Parent
| on HN ]
Re:Why is Zig so Cool?
by 1718627440 on Tuesday November 11, 2025 @08:44AM
(#45887199)
I don't use templates for that at all. Instead of:
Class * object = new (...);
I do: Class * object;
object = malloc (sizeof Class);
if (nullptr == object) // ... error handling
new (object) Class (...);
or if the constructor needs to fail: Class * object;
object = malloc (sizeof Class);
if (nullptr == object) // ... error handling
new (object) Class ();
if (!Class::init (object, ...)) {
object->~Class ();
free (object);
// ... other error handling
}