[bt-devel] Refactoring displaywindows classes; a future feature
Eeli Kaikkonen
eekaikko at mail.student.oulu.fi
Thu Nov 19 15:54:31 MST 2009
On Thu, 19 Nov 2009, Martin Gruner wrote:
> Eeli,
>
> > Also I want to
> > get rid of passing module pointers and use QStrings and QStringLists
> > which lessen the probability of crashes when modifying something. (As a
> > side note QString and QStringList copies shouldn't be afraid of, its
> > very cheap to copy them. See the Qt documentation for more.)
>
> I don't agree. It is never as cheap as copying a pointer. And if you just
> switch from pointers to QStringLists that doesn't change the problem of
> ownersphip. If you need to have a reference to a CSwordModuleInfo, a pointer
> is a good thing to do that. Maybe we should centralize the places where these
> pointers are held, but not copy around lists of module names.
I don't know if we mean same things. First, I'm not changing the
majority of messagin in text windows. I'm trying to find out how it
really works and meantime I noticed that it's better to change only the
module selector buttonbar/buttons. They don't actually need moduleinfo
in most places. And a window already has a list of modules, but as
string list! The pointer list is generated on-the-fly in a getter
method (I only put similar code in the backend). So, copying string
lists is actually cheaper.
In any case, the Qt documentation clearly says that "Implicitly
shared classes are both safe and efficient when passed as arguments" and
"you can pass instances of these classes as arguments to functions by
value without concern for the copying overhead". Actually, if I have
understood correctly, copying a QString or QStringList is about as cheap
as copying a reference counted pointer! And even if it wasn't, the
overhead is minimal in functions which are called only once in a row.
Some loops may of course be a different thing.
>
> Besides, a function called getPointerList is not a very specific name. :D
I can change that if needed, it's not used yet in other places so
changing doesn't have side effects. It may also be possible to revert
adding it if the code works without it - I'll explore it while I code.
Yours,
Eeli Kaikkonen (Mr.), Oulu, Finland
e-mail: eekaikko at mailx.studentx.oulux.fix (with no x)
More information about the bt-devel
mailing list