﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3ASource%2FData_Structures%2FDouble_Linked_List</id>
	<title>Dev:Source/Data Structures/Double Linked List - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3ASource%2FData_Structures%2FDouble_Linked_List"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:Source/Data_Structures/Double_Linked_List&amp;action=history"/>
	<updated>2026-05-21T04:03:50Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:Source/Data_Structures/Double_Linked_List&amp;diff=42358&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:Source/Data_Structures/Double_Linked_List&amp;diff=42358&amp;oldid=prev"/>
		<updated>2018-06-28T17:45:30Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2018年6月28日 (木) 17:45時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Yamyam</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:Source/Data_Structures/Double_Linked_List&amp;diff=42357&amp;oldid=prev</id>
		<title>wiki&gt;Jby601: /* Two Way Linked Dynamic List */ minor grammar tweaks</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:Source/Data_Structures/Double_Linked_List&amp;diff=42357&amp;oldid=prev"/>
		<updated>2012-01-08T09:02:24Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Two Way Linked Dynamic List: &lt;/span&gt; minor grammar tweaks&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Two Way Linked Dynamic List==&lt;br /&gt;
&lt;br /&gt;
Two Way Linked Dynamic List (later only &amp;quot;list&amp;quot;) is special dynamic data structure. You can see it very often in Blender source code. This dynamic data structure allows to add/remove dynamicaly allocated data structures. These data structures have to have special pointers (prev, next).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/* dynamicaly allocated dat structures has to include next and prev pointers */&lt;br /&gt;
typedef struct Link&lt;br /&gt;
{ &lt;br /&gt;
    struct Link *next,*prev;&lt;br /&gt;
} Link;&lt;br /&gt;
&lt;br /&gt;
/* ListBase points at the first and last pointer in dynamic list */&lt;br /&gt;
typedef struct ListBase &lt;br /&gt;
{ &lt;br /&gt;
    void *first, *last;&lt;br /&gt;
} ListBase;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every item has &amp;quot;next&amp;quot; and &amp;quot;prev&amp;quot; pointers (in this order) to make a two way dynamic list. &amp;quot;prev&amp;quot; points at the previous item in the list and &amp;quot;next&amp;quot; points to the next item in the list. The first item in the list has a NULL &amp;quot;prev&amp;quot; pointer and the last item in the list has a NULL &amp;quot;next&amp;quot; pointer.&lt;br /&gt;
&lt;br /&gt;
* Visualisation of Two Way Linked Dynamic List data strucuture: &amp;lt;br /&amp;gt;&lt;br /&gt;
[[File:Dev-two_way_dynamic_list.png|DynamicList]]&lt;br /&gt;
&lt;br /&gt;
We can simply &amp;quot;go&amp;quot; through the whole list (traverse the list) and do some testing or other operations:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
for (item = lb.first; item; item= item-&amp;gt;next) {&lt;br /&gt;
    do_some_operation_with_item();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can see this construction in source code very often.&lt;br /&gt;
&lt;br /&gt;
=== List of Available Functions ===&lt;br /&gt;
&lt;br /&gt;
We can use several functions, when we work with a list. You can find all of them in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
./source/blender/blenlib/intern/util.c&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
.h file with function prototypes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
./source/blender/blenlib/BLI_blenlib.h&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
List of functions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void addlisttolist(ListBase *list1, ListBase *list2);&lt;br /&gt;
void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink);&lt;br /&gt;
void * BLI_findlink(struct ListBase *listbase, int number);&lt;br /&gt;
void BLI_freelistN(struct ListBase *listbase);&lt;br /&gt;
void BLI_addtail(struct ListBase *listbase, void *vlink);&lt;br /&gt;
void BLI_remlink(struct ListBase *listbase, void *vlink);&lt;br /&gt;
void BLI_addhead(struct ListBase *listbase, void *vlink);&lt;br /&gt;
void BLI_insertlinkbefore(struct ListBase *listbase, void *vnextlink, void *vnewlink);&lt;br /&gt;
void BLI_freelist(struct ListBase *listbase);&lt;br /&gt;
int BLI_countlist(struct ListBase *listbase);&lt;br /&gt;
void BLI_freelinkN(struct ListBase *listbase, void *vlink);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Adding Item ====&lt;br /&gt;
&lt;br /&gt;
Simple example demonstrating adding new item to list:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef struct MyItem { &lt;br /&gt;
    struct MyItem *prev, *next; /* some other struct elements */ &lt;br /&gt;
    float vec[3];&lt;br /&gt;
} MyItem;&lt;br /&gt;
&lt;br /&gt;
struct ListBase lb={0,0};&lt;br /&gt;
&lt;br /&gt;
void my_function(void)&lt;br /&gt;
{ &lt;br /&gt;
    item = (Item*)MEM_callocN(sizeof(Item), &amp;quot;Item&amp;quot;);&lt;br /&gt;
     &lt;br /&gt;
    /* BLI_addtail will add item at the end of DynamicList */&lt;br /&gt;
    BLI_addtail(&amp;amp;lb, item);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can add item at the begining of list using BLI_addhead(&amp;amp;lb, item).&lt;br /&gt;
&lt;br /&gt;
==== Freeing of List ====&lt;br /&gt;
&lt;br /&gt;
We can free list using two different functions.&lt;br /&gt;
&lt;br /&gt;
''' BLI_freelist(ListBase '''*listbase) is used, when all items are allocated with malloc() function.&lt;br /&gt;
&lt;br /&gt;
''' BLI_freelistN(ListBase '''*listbase) is used, when all items are allocated with MEM_mallocN() function. MEM_mallocN() function is part of GuardedMalloc library. If you allocate items with MEM_mallocN() function, but you free [[Dev:Source/Data Structures/Dynamic List|DynamicList]] only with BLI_freelist() function, then Blender will print lot of debug messages about memory leaks.&lt;br /&gt;
&lt;br /&gt;
=== Writing List to .blend file ===&lt;br /&gt;
&lt;br /&gt;
You will have to modify some function in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
./source/blender/blenloader/intern/writefile.c&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and add construction like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
static void write_myitems(WriteData *wd, ListBase *lb) &lt;br /&gt;
{ &lt;br /&gt;
    Item item;&lt;br /&gt;
    for(item= lb-&amp;gt;first; item; item= item-&amp;gt;next)&lt;br /&gt;
        writestruct(wd, DATA, &amp;quot;MyItem&amp;quot;, 1, item);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reading List from .blend file ===&lt;br /&gt;
&lt;br /&gt;
Reading List is quite simple. You have to add one function at right place:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
FileData *fd;&lt;br /&gt;
ListBase *lb;&lt;br /&gt;
link_list(fd, lb);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;/div&gt;</summary>
		<author><name>wiki&gt;Jby601</name></author>
		
	</entry>
</feed>