Page MenuHome

Gardedalloc: Macro to use C++ 'new' operator with calloc
AbandonedPublic

Authored by Julian Eisel (Severin) on Dec 27 2015, 9:25 PM.

Details

Summary

Think this is useful for cases where objects with many members that should be zeroed by default need to be allocated. Setting them all manually is quite ugly and I guess it's also not that smart performance-wise.
Using memset(this, 0, sizeof(*this)) in the constructor should work too, but a) it's ugly having to do that manually again, b) member initializers become useless, and c) this can cause troubles when inheriting constructors (double zeroing).

Diff Detail

Repository
rB Blender
Branch
master

Event Timeline

Julian Eisel (Severin) retitled this revision from to Gardedalloc: Macro to use C++ 'new' operator with calloc.
Julian Eisel (Severin) updated this object.
Sergey Sharybin (sergey) requested changes to this revision.Dec 28 2015, 12:32 PM
Sergey Sharybin (sergey) edited edge metadata.

That's not a proper way to go and violates object paradigm. What OBJECT_GUARDED_NEW is:

  1. Allocate memory using Blender's guarded allocator
  2. Call object constructor to initialize the object in the newly allocated memory

It is up to the object to initialize it's members to whatever default value is preferred. It must not be up to the allocator to take care of object initialization.

This revision now requires changes to proceed.Dec 28 2015, 12:32 PM