<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On 24 October 2013 18:39, Thomas Martitz <span dir="ltr"><<a href="mailto:thomas.martitz@student.htw-berlin.de" target="_blank">thomas.martitz@student.htw-berlin.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am 24.10.2013 05:39, schrieb Lex Trotman:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
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.<br>

</blockquote>
<br>
The recycling & is_valid thing is completely bogus. It is wastes memory unnecessarily.<br></blockquote><div><br></div><div>Agreed.  I wasn't meaning to sound like I was defending it. I was just pointing out that one of its side effects.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
The is_valid thing is giving false security. Because a doc becomes valid again after it was recycled you cannot be sure that the document is still the same. Yet DOC_VALID() gives a false positive here if code missed the document-swap behind the scenes. So basically code that cares about GeanyDocument cannot rely on DOC_VALID() anyway.<br>
</blockquote><div><br></div><div>Indeed, it only ensures that a doc is valid, not that its the *same* document.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
The _only_ way to make sure things are alright is to cleanup per-document stuff in the "document-close" signal handler. If you don't connect to this signal your per-document code is broken, regardless of doc->is_valid. Even worse, this brokenness is hidden by valid doc pointers, whereas it would otherwise crash and suggest debugging the problem properly. The right way is to NULL'ify any cached document pointer in the signal-handler which makes recycling pointers unnecessary.<br>
</blockquote><div><br></div><div>Yes, just don't use pointers to closed documents.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Also, recycling the pointers is only possible because the document array never shrinks. So if you had opened a large number of documents and close many of them you waste a lot of memory.<br></blockquote><div><br></div><div>
Yes, I don't think the designers had people opening hundreds of documents in mind. :)  Although in the end the waste isn't all that great, but it doesn't need to happen.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
I vote for removing this idiom and transition the documents array to a GList which gives other nice advantages.<br></blockquote><div><br></div><div>Unfortunately there is an accessor document_index() in the plugin interface that uses the index into the array.</div>
<div><br></div><div>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.</div>
<div><br></div><div>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.</div>
<div><br></div><div>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 :)</div>
<div><br></div><div>Cheers</div><div>Lex</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Best regards.<br>
______________________________<u></u>_________________<br>
Devel mailing list<br>
<a href="mailto:Devel@lists.geany.org" target="_blank">Devel@lists.geany.org</a><br>
<a href="https://lists.geany.org/cgi-bin/mailman/listinfo/devel" target="_blank">https://lists.geany.org/cgi-<u></u>bin/mailman/listinfo/devel</a><br>
</blockquote></div><br></div></div>