your question seems to imply that there is one canonical objectB which doesn't move in memory however for whatever reason getObjectBFromSomewhere() is hard on memory but will always return a reference to this same object?
perhaps you're looking something like this:
//static means only available in this compilation unit
static const ObcjectB *obj = nullptr;
bool FunctionA (const ObjectA& a)
{
// ... some code ...
if(!obj)
obj = &getObjectBFromSomewhere(...);
const ObcjectB& b = *obj;
// ... code heavily reliant on b ...
return boolean_val;
}
bool FunctionB (const ObjectA& a)
{
bool boolean_val = FunctionA(a);
// ... some code ...
if(!obj)
obj = &getObjectBFromSomewhere(...);
const ObcjectB& b = *obj;
// ... code that only needs one tiny bit of b ...
return boolean_val;
}
if you're referring to the fact that functionA is called by functionB and therefore performs redundant work by calling getObjectBFromSomewhere() you could change the signature of functionA to accept a pointer to the object which it will use instead of calling getObjectFromSomewhere by itself i.e.
FunctionA(const ObjectA& a, ObcjectB *obj = nullptr)
{
if(!obj)
obj = &getObjectBFromSomewhere(...);
const ObcjectB& b = *obj;
}
and then change functionB to pass this param:
FunctionB (const ObjectA& a)
{
//move the expensive call up to the start of the method
const ObcjectB& b = getObjectBFromSomewhere(...);
bool boolean_val = FunctionA(a, &b);
// ... some code ...
// ... code that only needs one tiny bit of b ...
return boolean_val;
}