I have a big uncertanty about the cost of using references.
Either I don't know how to make the best of them, either this is the way things are.
I would like to know one's oppinion about this.
I am using a library which returns only references to objects. I have to use those references
throughout the program.
Now, if it was for pointers, I would have get that pointer and store in in 4 bytes of memory
and have no problems with it.
I really want to use pointers, so, because the library is using references,
I have to create copy-constructed objects and over and over again.
Here is a small example of what I am talking about:
1. When using Pointer returns:
2. When using References.
I know why the references were introduced and what's their purpose.
I also know that I could use a global or class-scope variable to store the reference, but
what if 1000 references are needed? Use an array of 1000 copy-constructed objects - even if reference counting is in place, which might be a performance add, after all?
The worst case is when the references returned IS a copy-constructed object, which adds
an extra constructor call inside the
It seems to me that the use of refs slows down the program and consumes memory.
What does anybody think about this? (especially Enigma, Zyrenthian & others...)
I may be missing something. [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
Either I don't know how to make the best of them, either this is the way things are.
I would like to know one's oppinion about this.
I am using a library which returns only references to objects. I have to use those references
throughout the program.
Now, if it was for pointers, I would have get that pointer and store in in 4 bytes of memory
and have no problems with it.
I really want to use pointers, so, because the library is using references,
I have to create copy-constructed objects and over and over again.
Here is a small example of what I am talking about:
1. When using Pointer returns:
Code:
SomeClass::someMethod()
{ a. Pointer* ptr = libraryObject.getSomethingAsPointer()
b. Use that pointer throughout the program.
c. If needed, delete it.
}
2. When using References.
Code:
SomeClass::someMethod()
{ a. Reference ref = libraryObject.getSomethingAsReference();
b. Pointer *ptr = new CopyConstructor(ref); // extra memory
c. move along...
d. when exiting the function, destructor for ref is called.
e. Use ptr throughout the program.
f. MUST Delete the pointer.
}
I know why the references were introduced and what's their purpose.
I also know that I could use a global or class-scope variable to store the reference, but
what if 1000 references are needed? Use an array of 1000 copy-constructed objects - even if reference counting is in place, which might be a performance add, after all?
The worst case is when the references returned IS a copy-constructed object, which adds
an extra constructor call inside the
Code:
libraryObject.getSomethingAsReference()
It seems to me that the use of refs slows down the program and consumes memory.
What does anybody think about this? (especially Enigma, Zyrenthian & others...)
I may be missing something. [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro