<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>HOW TO LOAD DATA FILE OBJECT...!!!!!!!!</title>
		<link>http://www.allegro.cc/forums/view/578194</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 14 Apr 2006 15:26:26 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>HI fellaws..</p><p>I am new to the data file concept...so..I wrote the below code in C to load a datafile containing only one object called &quot;image0.bmp&quot;. It get compiled fine without error but during the runtime..it shows window error and couldn&#39;t able to load the dat file..help me out please...</p><p>I have three files namely: main.c, grab_exp.h, and input.h</p><p>===================================================================================<br />This is my main.c file:</p><p>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;allegro.h&gt;<br />#include &quot;grab_exp.h&quot;<br />#include &quot;input.h&quot;</p><p>int main(int argc, char *argv[])<br />{<br />  allegro_init();<br />  <br />  DATAFILE *data_object;<br />  BITMAP *bmp;</p><p>      data_object = load_datafile_object (&quot;grab_exp.dat&quot;, &quot;image0&quot;);</p><p>      if (!data_object) {<br />         /* report an error! */<br />         return;<br />      }<br />      bmp = create_bitmap(SCREEN_W, SCREEN_H);<br />      bmp = (BITMAP *)data_object[image0].dat;<br />      blit(bmp, screen, 0, 0, 0, 0, bmp-&gt;w, bmp-&gt;h);<br />      <br />      destroy_bitmap(bmp);<br />      unload_datafile_object(data_object);<br />  <br />  allegro_exit();<br />  return 0;<br />}<br />END_OF_MAIN()</p><p>===================================================================================<br />This is my grab_exp.h</p><p>/* Allegro datafile object indexes, produced by grabber v4.0.3, MinGW32 */<br />/* Do not hand edit! */</p><p>#define image0                            0        /* BMP  */<br />//#define image1                            1        /* BMP  */<br />//#define image2                            2        /* BMP  */</p><p>===================================================================================<br />This is my input.h</p><p>extern DATAFILE *data_object;<br />extern BITMAP *bmp;</p><p>===================================================================================</p><p>So...actually what I want to do is to...load one object of datafile...I had thoroughly went through both vivace examples and allegro examples..still i couldn&#39;t able to load dat file...help needed in any form and in any way... PEACE
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tibgamer)</author>
		<pubDate>Mon, 10 Apr 2006 13:46:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You have a small error, the datafile code, in this case, the load_datafile_object creates the bitmap for you. There is no need to create_bitmap the bmp variable before hand, and leads to your actuall error, the destroy_bitmap (Freeing the bmp pointer twice), just use unload_datafile_object and you&#39;ll be fine.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 10 Apr 2006 13:55:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What Tomasu said, plus there are some errors and unnecessary lines.</p><p>These includes are useless:<br /><tt>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &quot;input.h&quot;</tt></p><p>You don&#39;t need the <tt>input.h</tt> file.</p><p>You need to set gfx mode to display graphics!</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
if (!data_object) {<br />/* report an error! */<br />return;<br />}
</p></div></div><p>The <tt>return</tt> here should return a numeric value, because it terminates the program&#39;s main function. E.g. <tt>return 1;</tt></p><p>It would be a good idea to e.g. wait for a key press before ending the program. Otherwise it&#39;ll execute in a fraction of a second.</p><p>Calling <tt>allegro_exit()</tt> is unnecessary.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Corelian)</author>
		<pubDate>Mon, 10 Apr 2006 14:12:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>And please put [code] and [/code] tags around your code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Mon, 10 Apr 2006 16:17:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>hi guys...as you had pointed out the errors..i had made the required changes...but still its not showing the dat object...whats wrong this time..help...</p><p>&lt;CODE&gt;</p><p>#include &lt;allegro.h&gt;<br />#include &quot;grab_exp.h&quot;</p><p>int main(int argc, char *argv[])<br />{<br />  allegro_init();<br />  install_keyboard();<br />  <br />  set_gfx_mode(GFX_AUTODETECT,640,480,0,0);<br />  <br />  DATAFILE *data_object;<br />  <br />      data_object = load_datafile_object (&quot;grab_exp.dat&quot;, &quot;image0&quot;);</p><p>      blit(data_object, screen, 0, 0, 0, 0, 30, 30);<br />      readkey();<br />      unload_datafile_object(data_object);<br />  <br />  return 0;<br />}<br />END_OF_MAIN()</p><p>&lt;/CODE&gt;<br /><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tibgamer)</author>
		<pubDate>Tue, 11 Apr 2006 11:03:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
blit(data_object, screen, 0, 0, 0, 0, 30, 30);
</p></div></div><p>Completely off the top of my head, but shouldn&#39;t it be <tt>data_object-&gt;dat</tt> there? Read the Allegro manual pages about datafiles. They contain plenty of examples.</p><p>Use [ and ] for those code tags. To see the available tags, click the &quot;[url <a href="http://www.allegro.cc/mockup.html">http://www.allegro.cc/mockup.html</a>] 	<br />HTML Mockup Code[/url] is enabled.&quot;-link above the text field when writing posts.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Corelian)</author>
		<pubDate>Tue, 11 Apr 2006 11:48:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>[quote ]shouldn&#39;t it be data_object-&gt;dat<br />&lt;/quote&gt;</p><p>well..i am new to allegro..so thats why am making lots of mistake..anway..i read the manual..and it says that struct DATAFILE consist:</p><p>   void *dat;     - pointer to the actual data<br />   int type;      - type of the data<br />   long size;     - size of the data in bytes<br />   void *prop;    - list of object properties<br /> <br />and since in my code...i had declared &quot;data_object&quot; as a pointer variable of struct DATAFILE...so..i guess..it is same as *dat..anyhow..i tried putting data_object-&gt;dat in blit..still its not working...!! Help..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tibgamer)</author>
		<pubDate>Tue, 11 Apr 2006 16:01:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Here&#39;s how it works.</p><p>A DATAFILE object holds information about a single datafile record. Not only the actual object data, but also its size, what kind of object it is, its name, original filename, and a few more properties.<br />When you do a load_datafile_object(), it does the following things for you:<br />1. Allocate memory for the datafile object<br />2. Load data from disk<br />3. Allocate memory for the actual object data<br />4. Load object data from disk<br />5. Return pointer to allocated data<br />So what you get in return is a pointer to a DATAFILE object, which in turn contains a pointer to the object it describes (in the dat field).<br />Since Allegro is a C library (not a C++ one), and the dat field can point to anything really (BITMAP, FONT, PALETTE, raw binary data, etc.), it is implemented as a void pointer. In plain C, this is no problem, but in C++, you need to explicitly cast the pointer to a BITMAP*:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span><span class="k2">)</span>data_object-&gt;dat, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">30</span>, <span class="n">30</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
Also, make sure that:<br />- data_object&#39;s type is actually DAT_BITMAP<br />- data_object is not NULL (indicating an error while loading)<br />- data_object-&gt;dat is not NULL (indicating that something else is wrong)<br />Either of these will give you unpleasant results.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Tue, 11 Apr 2006 16:34:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="p">#include &lt;allegro.h&gt;</span></td></tr><tr><td class="number">2</td><td><span class="p">#include "grab_exp.h"</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td>&#160;</td></tr><tr><td class="number">5</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span>argv<span class="k2">[</span><span class="k2">]</span><span class="k2">)</span></td></tr><tr><td class="number">6</td><td><span class="k2">{</span></td></tr><tr><td class="number">7</td><td><a href="http://www.allegro.cc/manual/allegro_init" target="_blank"><span class="a">allegro_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td><a href="http://www.allegro.cc/manual/install_keyboard" target="_blank"><span class="a">install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>&#160;</td></tr><tr><td class="number">10</td><td><a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span>GFX_AUTODETECT_WINDOWED,<span class="n">640</span>,<span class="n">480</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>&#160;</td></tr><tr><td class="number">12</td><td><a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>data_object<span class="k2">;</span></td></tr><tr><td class="number">13</td><td>&#160;</td></tr><tr><td class="number">14</td><td>data_object <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile_object" target="_blank"><span class="a">load_datafile_object</span></a> <span class="k2">(</span><span class="s">"grab_exp.dat"</span>, <span class="s">"image0"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td><a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span><span class="k2">)</span>data_object-&gt;dat, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">30</span>, <span class="n">30</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td><a href="http://www.allegro.cc/manual/readkey" target="_blank"><span class="a">readkey</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td><a href="http://www.allegro.cc/manual/unload_datafile_object" target="_blank"><span class="a">unload_datafile_object</span></a><span class="k2">(</span>data_object<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">19</td><td>&#160;</td></tr><tr><td class="number">20</td><td><span class="k1">return</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">21</td><td><span class="k2">}</span></td></tr><tr><td class="number">22</td><td><a href="http://www.allegro.cc/manual/END_OF_MAIN" target="_blank"><span class="a">END_OF_MAIN</span></a><span class="k2">(</span><span class="k2">)</span></td></tr></tbody></table></div></div><p>

This works perfectly here, if you don&#39;t want to look at the manual or at the examples please at least listen to others suggestions.</p><p>If it&#39;s not working, please describe exactly in which way is not working, assuming you didn&#39;t create a corrupted datafile.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (umperio)</author>
		<pubDate>Tue, 11 Apr 2006 16:48:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>hi all the guys above...</p><p>now..i am getting really cleared up..about the datafile concept..thanx a lot..now i could able to load one object of datafile on to the screen..,,now..i am trying to load more than one object onto the screen, i.e i had added one more object called &quot;image1&quot; in my dat file..and could successfully able to load it...though i have doubt like..there could be better way to load more than one object by using kinda arrays or stuff like that..so could you suggest any better way than the below codes....thanks a lot again...:-) PEACEEEE</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>&#160;</td></tr><tr><td class="number">2</td><td><span class="p">#include &lt;allegro.h&gt;</span></td></tr><tr><td class="number">3</td><td><span class="p">#include "grab_exp.h"</span></td></tr><tr><td class="number">4</td><td>&#160;</td></tr><tr><td class="number">5</td><td>&#160;</td></tr><tr><td class="number">6</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span>argv<span class="k2">[</span><span class="k2">]</span><span class="k2">)</span></td></tr><tr><td class="number">7</td><td><span class="k2">{</span></td></tr><tr><td class="number">8</td><td>   <a href="http://www.allegro.cc/manual/allegro_init" target="_blank"><span class="a">allegro_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>   <a href="http://www.allegro.cc/manual/install_keyboard" target="_blank"><span class="a">install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td>&#160;</td></tr><tr><td class="number">11</td><td>   <a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span>GFX_AUTODETECT_WINDOWED,<span class="n">640</span>,<span class="n">480</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td>&#160;</td></tr><tr><td class="number">13</td><td>   <a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>data_object, <span class="k3">*</span>data_object1<span class="k2">;</span></td></tr><tr><td class="number">14</td><td>   <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp<span class="k2">;</span></td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td>   bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_bitmap" target="_blank"><span class="a">create_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>   clear<span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td>   data_object <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile_object" target="_blank"><span class="a">load_datafile_object</span></a> <span class="k2">(</span><span class="s">"grab_exp.dat"</span>, <span class="s">"image0"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">19</td><td>   data_object1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile_object" target="_blank"><span class="a">load_datafile_object</span></a> <span class="k2">(</span><span class="s">"grab_exp.dat"</span>, <span class="s">"image1"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td>   <a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a><span class="k2">(</span>bmp, <span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span><span class="k2">)</span>data_object-&gt;dat, <span class="n">10</span>, <span class="n">10</span><span class="k2">)</span><span class="k2">;</span> </td></tr><tr><td class="number">21</td><td>   <a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a><span class="k2">(</span>bmp, <span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span><span class="k2">)</span>data_object1-&gt;dat, <span class="n">100</span>, <span class="n">100</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td>   <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>bmp, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>&#160;</td></tr><tr><td class="number">24</td><td>   </td></tr><tr><td class="number">25</td><td>   <a href="http://www.allegro.cc/manual/readkey" target="_blank"><span class="a">readkey</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">26</td><td>   <a href="http://www.allegro.cc/manual/unload_datafile_object" target="_blank"><span class="a">unload_datafile_object</span></a><span class="k2">(</span>data_object<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">27</td><td>   <a href="http://www.allegro.cc/manual/unload_datafile_object" target="_blank"><span class="a">unload_datafile_object</span></a><span class="k2">(</span>data_object1<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">28</td><td>   <a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">29</td><td>&#160;</td></tr><tr><td class="number">30</td><td><span class="k1">return</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">31</td><td><span class="k2">}</span></td></tr><tr><td class="number">32</td><td><a href="http://www.allegro.cc/manual/END_OF_MAIN" target="_blank"><span class="a">END_OF_MAIN</span></a><span class="k2">(</span><span class="k2">)</span></td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tibgamer)</author>
		<pubDate>Wed, 12 Apr 2006 11:24:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why don&#39;t you use a for loop for loading the objects? It should work fine. I remember doing this a very different way, but unfortunately I don&#39;t have the time now to check and post my code here. I might be able to do that later when I&#39;m back home.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CursedTyrant)</author>
		<pubDate>Wed, 12 Apr 2006 11:48:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s exactly what load_datafile() is for. Instead of painstakingly loading individual objects and managing memory for them, you can load an entire datafile into memory. RTFM to see what I mean. The basic idea is this:<br />1. Create your datafile using grabber or dat. I&#39;ll assume it&#39;s called &quot;data.dat&quot;.<br />2. Export datafile object names to a header file (the -h switch in dat.exe); I&#39;ll assume &quot;data.h&quot;.<br />3. In your main program, #include &quot;data.h&quot;<br />4. Use load_datafile() (after allegro_init() of course) to load the entire datafile into memory at once, like so:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a><span class="k3">*</span> data<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/allegro_init" target="_blank"><span class="a">allegro_init</span></a><span class="k2">(</span><span class="k2">)</span> <span class="c">// etc.; set up allegro nicely</span>
data <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile" target="_blank"><span class="a">load_datafile</span></a><span class="k2">(</span><span class="s">"data.dat"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
5. data now contains an array of DATAFILE objects, and the header you included gives you handy defines to access them directly and with virtually no performance overhead, like this:
</p><div class="source-code snippet"><div class="inner"><pre><span class="c">// assuming you have loaded the datafile, and there is an image called "image1.bmp" in it:</span>
<a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span><span class="k2">)</span>data<span class="k2">[</span>IMAGE1_BMP<span class="k2">]</span><span class="k3">-</span><span class="k3">&gt;</span>dat, <span class="n">100</span>, <span class="n">100</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
And at the end of your program, you should free the memory allocated by the datafile array by calling:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/unload_datafile" target="_blank"><span class="a">unload_datafile</span></a><span class="k2">(</span>data<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Wed, 12 Apr 2006 12:10:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
That&#39;s exactly what load_datafile() is for. Instead of painstakingly loading individual objects and managing memory for them, you can load an entire datafile into memory.
</p></div></div><p>
Which is a horrible idea if you&#39;re only going to need a small portion of the datafile loaded into memory at any given time. Not wasting memory is A Good Thing(tm) <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Wed, 12 Apr 2006 12:14:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Not over-complicating code is also a Good Thing. A typical newbie game is small, so small that the amount of data in memory is a non-issue. Loading datafile objects one by one requires you to keep track of each one individually, and every time you add an object to the datafile, you need to change the loading code. This creates a lot of opportunities for nasty bugs and memory leaks - not exactly what a beginning programmer is waiting for.<br />Also, one would typically use all the objects in the datafile anyway, so loading them all at once won&#39;t consume that much more memory (might even be less by avoiding loading objects twice).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Wed, 12 Apr 2006 12:29:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Loading datafile objects one by one requires you to keep track of each one individually, and every time you add an object to the datafile, you need to change the loading code.
</p></div></div><p>
No you don&#39;t.<br /><span class="source-code">data_object <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile_object" target="_blank"><span class="a">load_datafile_object</span></a> <span class="k2">(</span><span class="s">"grab_exp.dat"</span>, <span class="s">"image0"</span><span class="k2">)</span><span class="k2">;</span></span><br />will always load the object named &quot;image0&quot; into data_object. You can add or remove things in the datafile as you want, and as long as image0 is the same, it&#39;ll work. Now, if you were loading the whole datafile at once, you&#39;d have to recompile the parts of the program that made use of it, since the indices would change and the header would have to be remade since the values changed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Wed, 12 Apr 2006 13:10:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Of course this is absolutely true. On the other hand, one typically <i>loads</i> the objects in one part of the program (initialization), while <i>using</i> them in another part (main loop, or even entity member func). If these parts are in different files, things get hackish. If they aren&#39;t, you just use indices into the global sprite list; if you try to use something that&#39;s not there, the compiler will throw it in your face. To be safe, you can set up your compile process to create the header every time, or use find_datafile_object().
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Wed, 12 Apr 2006 13:21:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>hi guys...</p><p>now..i am trying to add SAMPLE file in my dat file..but i couldn&#39;t able to play it through dat file..though i could play it separately like below...tell me how to load the SAMPLE file called &quot;frog&quot; from dat file and play it from dat file....</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>&#160;</td></tr><tr><td class="number">2</td><td><span class="p">#include &lt;allegro.h&gt;</span></td></tr><tr><td class="number">3</td><td><span class="p">#include "grab_exp.h"</span></td></tr><tr><td class="number">4</td><td>&#160;</td></tr><tr><td class="number">5</td><td>&#160;</td></tr><tr><td class="number">6</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span>argv<span class="k2">[</span><span class="k2">]</span><span class="k2">)</span></td></tr><tr><td class="number">7</td><td><span class="k2">{</span></td></tr><tr><td class="number">8</td><td>   <a href="http://www.allegro.cc/manual/allegro_init" target="_blank"><span class="a">allegro_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>   <a href="http://www.allegro.cc/manual/install_keyboard" target="_blank"><span class="a">install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td>&#160;</td></tr><tr><td class="number">11</td><td>   <a href="http://www.allegro.cc/manual/set_color_depth" target="_blank"><span class="a">set_color_depth</span></a><span class="k2">(</span><span class="n">32</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td>   <a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span>GFX_AUTODETECT_WINDOWED,<span class="n">640</span>,<span class="n">480</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>&#160;</td></tr><tr><td class="number">14</td><td>   <a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>data_object, <span class="k3">*</span>data_object1<span class="k2">;</span></td></tr><tr><td class="number">15</td><td>   <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp<span class="k2">;</span></td></tr><tr><td class="number">16</td><td>   <a href="http://www.allegro.cc/manual/SAMPLE" target="_blank"><span class="a">SAMPLE</span></a> <span class="k3">*</span>music_object<span class="k2">;</span></td></tr><tr><td class="number">17</td><td>&#160;</td></tr><tr><td class="number">18</td><td>   bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_bitmap" target="_blank"><span class="a">create_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">19</td><td>   clear<span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td>      </td></tr><tr><td class="number">21</td><td>   data_object <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile_object" target="_blank"><span class="a">load_datafile_object</span></a> <span class="k2">(</span><span class="s">"grab_exp.dat"</span>, <span class="s">"image0"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td>   data_object1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile_object" target="_blank"><span class="a">load_datafile_object</span></a> <span class="k2">(</span><span class="s">"grab_exp.dat"</span>, <span class="s">"image1"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>   </td></tr><tr><td class="number">24</td><td>   </td></tr><tr><td class="number">25</td><td>   <a href="http://www.allegro.cc/manual/install_sound" target="_blank"><span class="a">install_sound</span></a><span class="k2">(</span>DIGI_AUTODETECT, MIDI_AUTODETECT, NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">26</td><td>   music_object <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_sample" target="_blank"><span class="a">load_sample</span></a><span class="k2">(</span><span class="s">"Frog.wav"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">27</td><td>   </td></tr><tr><td class="number">28</td><td>   <a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a> <span class="k2">(</span>bmp, <span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span><span class="k2">)</span>data_object-&gt;dat, <span class="n">10</span>, <span class="n">10</span><span class="k2">)</span><span class="k2">;</span> </td></tr><tr><td class="number">29</td><td>   <a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a> <span class="k2">(</span>bmp, <span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span><span class="k2">)</span>data_object1-&gt;dat, <span class="n">100</span>, <span class="n">100</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">30</td><td>   <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a> <span class="k2">(</span>bmp, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">31</td><td>   </td></tr><tr><td class="number">32</td><td>      </td></tr><tr><td class="number">33</td><td>   <a href="http://www.allegro.cc/manual/play_sample" target="_blank"><span class="a">play_sample</span></a><span class="k2">(</span>music_object, <span class="n">300</span>, <span class="n">128</span>, <span class="n">1000</span>, TRUE<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">34</td><td>   </td></tr><tr><td class="number">35</td><td>   <a href="http://www.allegro.cc/manual/readkey" target="_blank"><span class="a">readkey</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">36</td><td>   <a href="http://www.allegro.cc/manual/unload_datafile_object" target="_blank"><span class="a">unload_datafile_object</span></a><span class="k2">(</span>data_object<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">37</td><td>   <a href="http://www.allegro.cc/manual/unload_datafile_object" target="_blank"><span class="a">unload_datafile_object</span></a><span class="k2">(</span>data_object1<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">38</td><td>   <a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">39</td><td>   <a href="http://www.allegro.cc/manual/destroy_sample" target="_blank"><span class="a">destroy_sample</span></a><span class="k2">(</span>music_object<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">40</td><td>&#160;</td></tr><tr><td class="number">41</td><td><span class="k1">return</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">42</td><td><span class="k2">}</span></td></tr><tr><td class="number">43</td><td><a href="http://www.allegro.cc/manual/END_OF_MAIN" target="_blank"><span class="a">END_OF_MAIN</span></a><span class="k2">(</span><span class="k2">)</span></td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tibgamer)</author>
		<pubDate>Wed, 12 Apr 2006 16:38:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You should use it just the same as bitmap objects:
</p><div class="source-code snippet"><div class="inner"><pre>   <a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>music_object<span class="k2">;</span>   
   music_object <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_sample" target="_blank"><span class="a">load_sample</span></a><span class="k2">(</span><span class="s">"Frog.wav"</span><span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/play_sample" target="_blank"><span class="a">play_sample</span></a><span class="k2">(</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/SAMPLE" target="_blank"><span class="a">SAMPLE</span></a><span class="k3">*</span><span class="k2">)</span>music_object-&gt;dat, <span class="n">300</span>, <span class="n">128</span>, <span class="n">1000</span>, TRUE<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Of course you could wrap some stuff around loading datafile to get the pointers to the dat fields when loading files. </p><p>I once did a very cleaver datafile loading class for my Xcom engine. All it needed was the datafile name and a text file describing the tile layers. When I loaded the file everything else worked automagically <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>[edit]</p><p>oops, I think I made a mistake. I have never used sounds in Allegro and I didn&#39;t notice that load_sample returs sample directly. That code should work if you replace the load_sample with load_datafile_object.</p><p>Also, it seems like load_sample loads stuff frome external files, not from datafiles. If you would check the return values I&#39;m sure you would have an error in the load_sample function.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (HoHo)</author>
		<pubDate>Wed, 12 Apr 2006 16:44:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
tell me how to load the SAMPLE file called &quot;frog&quot; from dat file and play it from dat file....
</p></div></div><p>

...please</p><p>Since it seems to me you&#39;re still learning, I&#39;d go for a complete datafile instead of loading all the objects separately.</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="p">#include &lt;allegro.h&gt;</span></td></tr><tr><td class="number">2</td><td><span class="p">#include "running.h"</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td>&#160;</td></tr><tr><td class="number">5</td><td><span class="k1">void</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">6</td><td>    <a href="http://www.allegro.cc/manual/allegro_init" target="_blank"><span class="a">allegro_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">7</td><td>    <a href="http://www.allegro.cc/manual/install_keyboard" target="_blank"><span class="a">install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>    </td></tr><tr><td class="number">9</td><td>    <a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span>GFX_AUTODETECT_WINDOWED, <span class="n">640</span>, <span class="n">480</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td>    <a href="http://www.allegro.cc/manual/install_sound" target="_blank"><span class="a">install_sound</span></a><span class="k2">(</span>DIGI_AUTODETECT, MIDI_AUTODETECT, NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>    </td></tr><tr><td class="number">12</td><td>    <a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>data<span class="k2">;</span></td></tr><tr><td class="number">13</td><td>    </td></tr><tr><td class="number">14</td><td>    data <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile" target="_blank"><span class="a">load_datafile</span></a><span class="k2">(</span><span class="s">"running.dat"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td>    <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>data<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">17</td><td>        <a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"Error loading data"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">19</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">20</td><td>    </td></tr><tr><td class="number">21</td><td>    <a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span><span class="k2">)</span>data<span class="k2">[</span>FRAME_01<span class="k2">]</span>.dat, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td>    <a href="http://www.allegro.cc/manual/play_sample" target="_blank"><span class="a">play_sample</span></a><span class="k2">(</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/SAMPLE" target="_blank"><span class="a">SAMPLE</span></a> <span class="k3">*</span><span class="k2">)</span>data<span class="k2">[</span>SOUND_01<span class="k2">]</span>.dat, <span class="n">255</span>, <span class="n">128</span>, <span class="n">1000</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>    </td></tr><tr><td class="number">24</td><td>    <a href="http://www.allegro.cc/manual/readkey" target="_blank"><span class="a">readkey</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">25</td><td>    </td></tr><tr><td class="number">26</td><td>    <a href="http://www.allegro.cc/manual/unload_datafile" target="_blank"><span class="a">unload_datafile</span></a><span class="k2">(</span>data<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">27</td><td><span class="k2">}</span></td></tr><tr><td class="number">28</td><td><a href="http://www.allegro.cc/manual/END_OF_MAIN" target="_blank"><span class="a">END_OF_MAIN</span></a><span class="k2">(</span><span class="k2">)</span></td></tr></tbody></table></div></div><p>

Here I used the file running.dat from the allegro examples. Did you ever take a look at them?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (umperio)</author>
		<pubDate>Wed, 12 Apr 2006 21:10:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can always do load_bitmap(&quot;datafile.dat#bitmapname&quot;) too.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Thu, 13 Apr 2006 05:11:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
it seems to me you&#39;re still learning
</p></div></div><p>

yes..i have just started out with allegro..and i have been going through the vivace tutorial..for a week or so....thats why am making lots of errors..anway..thanx for helping me out...i have been learning a lot from this forum....</p><p>oh..yes..now i could able to play SAMPLE file from dat file..Could any one tell me how to create header file index of objects from grabber..i tried going to Object menu and click export...but couldn&#39;t able to make header file...help me...!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tibgamer)</author>
		<pubDate>Thu, 13 Apr 2006 11:29:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why don&#39;t you read how to do it?<br />There&#39;s a file called &quot;grabber.txt&quot; which can help you:</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
===========================================<br />============ Using the grabber ============<br />===========================================</p><p>Various options can be set using the buttons and text fields at the top of <br />the screen. You can edit the name of the datafile, the name of the header <br />file for exporting object indexes (leave this blank if you don&#39;t want to <br />output a header), and the prefix string for the header file definitions.
</p></div></div><p>

Regards
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (umperio)</author>
		<pubDate>Thu, 13 Apr 2006 12:47:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>My, umperio, that&#39;s a mighty friendly RTFM, I say.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Fri, 14 Apr 2006 15:19:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>thanks..i will check out...!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tibgamer)</author>
		<pubDate>Fri, 14 Apr 2006 15:26:26 +0000</pubDate>
	</item>
</rss>
