From c1983bad481be1ac904f77322076208a072e9f40 Mon Sep 17 00:00:00 2001 From: ejakowatz Date: Tue, 29 Oct 2002 21:27:44 +0000 Subject: [PATCH] Rewrote the "adding more data" section to deal with missing destructor problem. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1771 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- docs/develop/ikteam/BinCompat.html | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/develop/ikteam/BinCompat.html b/docs/develop/ikteam/BinCompat.html index 6048e871c8..51524fbb3e 100644 --- a/docs/develop/ikteam/BinCompat.html +++ b/docs/develop/ikteam/BinCompat.html @@ -76,6 +76,7 @@ should be binary compatible in no time! class BFoo { public: BFoo(); + ~BFoo(); void SomeFunc(); private: int32 fBar; @@ -117,7 +118,7 @@ should be binary compatible in no time! int32s worth of data: fNewData1 through fNewData4. The original implementation of BFoo has two extra int32s which we can use, but that leaves us two int32s - short. What to do? The easiest thing to do is create a data structure to hold + short. What to do? The easiest thing is to create a data structure to hold your new data and convert one of the fUnused items into a pointer to that structure: @@ -155,8 +156,12 @@ should be binary compatible in no time! } - Voila! More data without making the class bigger. Notice the added - destructor; make sure you're cleaning up your new (dynamically allocated) data. + Voila! More data without making the class bigger. Make sure you're cleaning up + your new (dynamically allocated) data in the destructor. NOTE: this trick + will only work if the class originally had a destructor! Adding a destructor + after the fact won't work for existing apps (since they won't call it), leading + to memory leaks. Fortunately, there are very few instances in the BeAPI where a + class doesn't have a destructor already declared.