[Geany-Devel] On document pointer recycling
Thomas Martitz
thomas.martitz at xxxxx
Thu Oct 24 08:31:43 UTC 2013
Am 24.10.2013 10:22, schrieb Lex Trotman:
>
>
>
> On 24 October 2013 18:39, Thomas Martitz
> <thomas.martitz at student.htw-berlin.de
> <mailto:thomas.martitz at student.htw-berlin.de>> wrote:
>
> Am 24.10.2013 05:39, schrieb Lex Trotman:
>
>
>
> PS On the recycling of doc structures and doc->is_valid, this
> does have the advantage (for a structure where miscellaneous
> pointers to the structure are going to exist in Geany and
> plugins) that doc pointers will always point to a
> geanydocument struct. So the is_valid test is always right.
> If the memory was returned and re-cycled into some other
> struct, the old doc pointers could point to anything, and
> could just as easily appear a valid document. So its safer
> than the alternative, but the requirement to check is_valid
> really does need more visibility since its an unusual idiom.
>
>
> The recycling & is_valid thing is completely bogus. It is wastes
> memory unnecessarily.
>
>
> Agreed. I wasn't meaning to sound like I was defending it. I was just
> pointing out that one of its side effects.
Yes you sounded like that.
> I vote for removing this idiom and transition the documents array
> to a GList which gives other nice advantages.
>
>
> Unfortunately there is an accessor document_index() in the plugin
> interface that uses the index into the array.
>
> Switching to a list means that there needs to be a change everywhere
> in Geany and the plugins that the array index is used instead of a
> pointer. I don't see anywhere where the index is used inside Geany
> but I may have missed somewhere. I don't know how often its used by
> plugins. But again its use could be deprecated and a temporary map
> (eg g_tree) from an int to the pointer could be used until plugins are
> modified.
>
> All the places where Geany and plugins iterate over the document list
> also needs to be replaced by a loop using g_list_first() and
> g_list_next(). I count 12 or 13 such places in Geany itself, but I
> don't know how many there are in plugins.
>
> Its certainly not a one line change, but may not be huge, depending on
> the plugins use of the index. However I wouldn't call it a high
> priority change, even a thousand geanydocument structs isn't much
> memory compared to the amount Scintilla uses :)
>
Okay, but you still agree that doc->is_valid should be removed
eventually? That's a step forward :)
Best regards.
More information about the Devel
mailing list