Wann sind local references sinnvoll?



  • In einem Text steht:

    local references are sometimes used to avoid recalculating the same loction several times; they allow a function to attach a handle to an object that would otherwise require nontrivial address computation to access. Applications that do a lot of cacheing sometimes use local references.

    Kann mir jemand das mal erklaeren? So wie es dort steht, kann ich damit nicht viel anfangen.



  • void f(Foo* bla){
       bla->member.child.add(5);
       bla->member.child.mul(3);
       bla->member.child.div(7);
    }
    
    void f(Foo* bla){
       Bar& c=bla->member.child;
       c.add(5);
       c.mul(3);
       c.div(7);
    }
    

    edit: noich viel stärker, mit

    map<string,int> bla;
    ...
    bla[str].add(5);
    bla[str].mul(5);
    bla[str].div(5);
    

    jedemal den teuren op[] mit laufzeit log(bla.size()) zu machen wäre fürchterbar.


Anmelden zum Antworten