[Geany-Devel] On document pointer recycling

Dimitar Zhekov dimitar.zhekov at xxxxx
Fri Oct 25 18:28:38 UTC 2013

On Fri, 25 Oct 2013 08:51:30 +1100
Lex Trotman <elextr at gmail.com> wrote:

> > That being said, just how is a list better than a GPtrArray?
> True, its the fact that the index is held constant because it might be
> stored and re-used that stops the array from being shrunk.  Getting rid of
> the use of indexes is the necessary pre-condition for shrinking the array,
> or using a list or whatever.

>From what I've seen, the indexes are always used immediately for
documens[i]. Whoever wants to store reference to a document does that
by using a doc pointer, and when we start to free doc-s, these pointers
will be affected, no matter what container is used. Whether we will use
reference counting to protect them, or require the doc holder to handle
"document-close", is also irrelevant to my question.

It's the closed documents that are held, not the indexes. If we start
to free documents, there is nothing to stop us from doing that with
g_ptr_array_remove_index() or g_ptr_array_remove(). Sure, if you
remove a document inside a foreach_document() loop, you'll have to
decrement the loop variable, but that's to be expected in C, and
extremely rare.

E-gards: Jimmy

More information about the Devel mailing list