🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #775

Re: Fast acces to class method

#775
From: Karl Heinz Buchegger
Date: Wed, 22 Mar 2000 00:00
48 lines
1918 bytes

dataman@cyberdude.com wrote:
> 
> What is the fastest way for  accessing a member  in  a class.
> 
> DATA is a structure;
> 
> class A
> {
>   public:
>             //directly by having access to the member ?
>             DATA data;
> 
>             //by return value
>             DATA GetData()
>             {
>               return data;
>             }
> 
>            //by reference
>            void GetData(DATA& d)
>            {
>               d=data;
>            }
> 
>            //by pointer
>            void GetData(DATA* pD)
>            {
>             *pData=data;
>            }
> }
> 

All your methods (except the direct access) depend
on copying the complete structure. Why not giving
away a pointer to data.

   inline const DATA* GetData() { return &data; };

for accessing, everybody can get a pointer to your structure
but nobody is allowed to change the contents of the structure.

-----------------------------------------------------------
Karl Heinz Buchegger
kbuchegg@gascad.at
++43 7258 7545 23
Fuer sehr grosse Werte von 2 gilt: 2 + 2 = 5
Technical Details
Message-ID: <38D8F092.AB4E83CC@gascad.at>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <38D8E693.34731AA0@cyberdude.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114592,d558f056865fc0f1
X-Google-Attributes: gid114592,public
X-Google-Thread: 109fba,d558f056865fc0f1
X-Google-Attributes: gid109fba,public
X-Google-Thread: fdcad,d558f056865fc0f1
X-Google-Attributes: gidfdcad,public
From: Karl Heinz Buchegger <kbuchegg@gascad.at>
Subject: Re: Fast acces to class method
Date: 2000/03/22
Message-ID: <38D8F092.AB4E83CC@gascad.at>
X-Deja-AN: 600900925
Content-Transfer-Encoding: 7bit
References: <38D8E693.34731AA0@cyberdude.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Trace: newsreader.vienna.highway.telekom.at 953741454 83134 212.183.121.231
Organization: GASCAD
MIME-Version: 1.0
Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c++,fr.comp.lang.c++