C++11 Shared Pointers Make Leadwerks 5 Simpler
This shows the fundamental difference between shared pointers and manual reference counting.
Leadwerks 4:
void Material::SetTexture(Texture* texture, const int index) { if (this->texture[index] != texture) { if (this->texture[index]) this->texture[index]->Release(); this->texture[index] = texture; if (this->texture[index]) this->texture[index]->AddRef(); } }
Leadwerks 5:
void Material::SetTexture(shared_ptr<Texture> texture, const int index) { this->texture[index] = texture; }
The second example automatically does the same thing as the first (basically) but you don't have to worry about making mistakes. When the texture is no longer referred to by any variable, it will be automatically deleted from system and video memory.
- 1
1 Comment
Recommended Comments