CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2
  • Faltering Windows support
  • Internet Explorer 8 Click Clever Click Safe
  • Release Candidate 2 for ASP.NET MVC 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 21st, 2009, 12:23 PM
    hoangtuansu hoangtuansu is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 3
    hoangtuansu is an unknown quantity at this point (<10)
    The main disadvantage of C++ Object Model

    Hello,

    I've been reading the "Inside C++ Object Model" and when reach to the 1.1 section - "The C++ Object Model" I can't understand the content of author. That's as following:

    <b>Stroustrup's original (and still prevailing) C++ Object Model is derived from the simple object model by optimizing for space and access time. Nonstatic data members are allocated directly within each class object. Static data members are stored outside the individual class object. Static and nonstatic function members are also hoisted outside the class object. Virtual functions are supported in two steps:

    A table of pointers to virtual functions is generated for each class (this is called the virtual table).

    A single pointer to the associated virtual table is inserted within each class object (traditionally, this has been called the vptr). The setting, resetting, and not setting of the vptr is handled automatically through code generated within each class constructor, destructor, and copy assignment operator (this is discussed in Chapter 5). The type_info object associated with each class in support of runtime type identification (RTTI) is also addressed within the virtual table, usually within the table's first slot.

    Figure 1.3 illustrates the general C++ Object Model for our Point class. The primary strength of the C++ Object Model is its space and runtime efficiency. Its primary drawback is the need to recompile unmodified code that makes use of an object of a class for which there has been an addition, removal, or modification of the nonstatic class data members. (The two table model, for example, offers more flexibility by providing an additional level of indirection. But it does this at the cost of space and runtime efficiency.)</b>

    He said the the main drawback is to recompile the unmodified code but I can imagine that situation. Anyone can give me several examples for that?

    Thanks,
    HTS
    Reply With Quote
      #2    
    Old November 21st, 2009, 01:44 PM
    Lindley Lindley is online now
    Elite Member
    Power Poster
     
    Join Date: Oct 2007
    Location: Fairfax, VA
    Posts: 6,902
    Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+)
    Re: The main disadvantage of C++ Object Model

    Basically it's a complicated way of saying that if you modify a class, you need to recompile all code which uses that class, even if the modification wouldn't affect the operation of said code directly.
    Reply With Quote
      #3    
    Old November 21st, 2009, 03:12 PM
    treuss's Avatar
    treuss treuss is offline
    Elite Member
     
    Join Date: Jan 2004
    Location: Düsseldorf, Germany
    Posts: 2,331
    treuss is a splendid one to behold (750+) treuss is a splendid one to behold (750+) treuss is a splendid one to behold (750+) treuss is a splendid one to behold (750+) treuss is a splendid one to behold (750+) treuss is a splendid one to behold (750+) treuss is a splendid one to behold (750+) treuss is a splendid one to behold (750+)
    Re: The main disadvantage of C++ Object Model

    May I add two things to this.

    1. The disadvantage becomes a big problem if you are writing libraries.

    Imagine you are a commercial vendor of a library, thus you provide to your customers header files and the compiled library code. Your customers build your applications based on it. Now you want to fix a bug or optimize something which requires you to change you object members. Even though the change is within the private: section of your class and is perfectly encapsulated, your customers cannot just plugin the new version of your library but have to recompile ALL code that uses the library. Thus you can really only do such changes if you are rolling out a new major release of your library.

    2. There is a way to get around this disadvantage (at the cost of space and runtime efficiency), which is the pimpl idiom. Most library vendors use that.
    __________________
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth

    Computer programming requires a great deal of attention to detail and an ability to read and understand abstract instructions. Posting a question to this forum in a way that it will get answered, requires the same, though too far smaller degree. Thus, if you don't get your question answered here, maybe it's time to accept that programming is not your thing. --Yours truly

    Please read Information on posting before posting, especially the info on using [code] tags.
    Reply With Quote
      #4    
    Old November 22nd, 2009, 04:13 AM
    Zaccheus's Avatar
    Zaccheus Zaccheus is offline
    Elite Member
     
    Join Date: Apr 2004
    Location: England, Europe
    Posts: 2,243
    Zaccheus is a name known to all (1000+) Zaccheus is a name known to all (1000+) Zaccheus is a name known to all (1000+) Zaccheus is a name known to all (1000+) Zaccheus is a name known to all (1000+) Zaccheus is a name known to all (1000+) Zaccheus is a name known to all (1000+) Zaccheus is a name known to all (1000+)
    Re: The main disadvantage of C++ Object Model

    Quote:
    Originally Posted by hoangtuansu View Post
    Its primary drawback is the need to recompile unmodified code that makes use of an object of a class for which there has been an addition, removal, or modification of the nonstatic class data members.

    Anyone can give me several examples for that?
    Seem quite simple to me: If your class contains a 3rd part class' instance as a data member and the size of that 3rd part class changes, you have to recompile your class.

    Code:
    class MyClass
    {
    public:
    //...
    
    private:
    //...
    
    Some3rdPartyClass    myDatamember;
    };
    __________________
    My hobby projects:
    www.rclsoftware.org.uk
    Reply With Quote
      #5    
    Old November 22nd, 2009, 05:24 AM
    originalfamousjohnsmith originalfamousjohnsmith is offline
    Member
     
    Join Date: Aug 2009
    Posts: 94
    originalfamousjohnsmith is an unknown quantity at this point (<10)
    Re: The main disadvantage of C++ Object Model

    Pointers work the same as the 'pimpl idiom' in this regard, and can allow you to not include it in your header at all which can be very nice.
    Reply With Quote
      #6    
    Old November 22nd, 2009, 07:25 AM
    laserlight laserlight is online now
    Elite Member
    Power Poster
     
    Join Date: Jan 2006
    Location: Singapore
    Posts: 4,123
    laserlight is a name known to all (1000+) laserlight is a name known to all (1000+) laserlight is a name known to all (1000+) laserlight is a name known to all (1000+) laserlight is a name known to all (1000+) laserlight is a name known to all (1000+) laserlight is a name known to all (1000+) laserlight is a name known to all (1000+) laserlight is a name known to all (1000+) laserlight is a name known to all (1000+)
    Re: The main disadvantage of C++ Object Model

    Quote:
    Originally Posted by originalfamousjohnsmith
    Pointers work the same as the 'pimpl idiom' in this regard, and can allow you to not include it in your header at all which can be very nice.
    Well, pimpl means "pointer to implementation", and no, just using a pointer without using the pimpl idiom will not work the same. Sure, a forward declaration in the client code's header would suffice, but when it comes to defining the functions of the client code that actually use objects of the given class, the class definition must be available, and the client code will still need to be re-compiled if "there has been an addition, removal, or modification of the nonstatic class data members" of that class.
    __________________
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful
    Reply With Quote
      #7    
    Old November 22nd, 2009, 11:49 AM
    hoangtuansu hoangtuansu is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 3
    hoangtuansu is an unknown quantity at this point (<10)
    Re: The main disadvantage of C++ Object Model

    In that book, the writter suggested 3 models:

    - A Simple Object Model: in which an object contains an array of slots. And every slot is a pointer which point to the available field or method. Apparently, we also need to recompile if there's any modification or addition.

    - A Table - Driven Object Model: an object just consists of two pointers, one points to member data table, and one points to funtion member table. And in my opinion, this approach can be solve the problem of the C++ Object Model as I mentioned on the first post.

    Anyway, I think that the solution of truess is the same as the approach of creating COM technology which is in the "Essential COM" :-)

    Thanks all,
    HTS
    Reply With Quote
      #8    
    Old November 22nd, 2009, 11:50 AM
    hoangtuansu hoangtuansu is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 3
    hoangtuansu is an unknown quantity at this point (<10)
    Re: The main disadvantage of C++ Object Model

    Sorry, I forgot. The third model is "The C++ Object Model"
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 12:38 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.