Skip to Main Content
3D Game Engine Design, 2nd Edition
book

3D Game Engine Design, 2nd Edition

by David Eberly
November 2006
Intermediate to advanced content levelIntermediate to advanced
1040 pages
26h 31m
English
CRC Press
Content preview from 3D Game Engine Design, 2nd Edition
808 Chapter 18 Object-Oriented Infrastructure
Node* pkNode = new Node;
MyFunction(pkNode);
// pkNode now points to invalid memory
On allocation pkNode has zero references. The call to MyFunction creates an instance
of a
NodePtr on the stack via the copy constructor for that class. That call increments
the reference count of
pkNode to one. On return from the function, the instance of
NodePtr is destroyed and, in the process, pkNode has zero references and it too is
destroyed. However, the following code is safe:
Node* pkNode = new Node; // pkNode references = 0
NodePtr spkNode = pkNode; // pkNode references = 1;
MyFunction(spkNode); // pkNode references increase to 2,
// then decrease to 1
// pkNode references=1atthis point
A related problem is
NodePtr MyFunction ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

3D Game Engine Architecture

3D Game Engine Architecture

David Eberly
Blender 3D By Example - Second Edition

Blender 3D By Example - Second Edition

Oscar Baechler, Xury Greer
Computer Graphics

Computer Graphics

Alexey Boreskov, Evgeniy Shikin

Publisher Resources

ISBN: 9781482267303