<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-3%3Asbas046</id>
	<title>SE250:lab-3:sbas046 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-3%3Asbas046"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:sbas046&amp;action=history"/>
	<updated>2026-04-28T16:17:51Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:lab-3:sbas046&amp;diff=5742&amp;oldid=prev</id>
		<title>Mark: 2 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:sbas046&amp;diff=5742&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:27Z</updated>

		<summary type="html">&lt;p&gt;2 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Task 1 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for n = 1000000&lt;br /&gt;
it takes 47 ticks&lt;br /&gt;
&lt;br /&gt;
for n = 10000000&lt;br /&gt;
it takes 594 ticks&lt;br /&gt;
&lt;br /&gt;
for n = 20000000&lt;br /&gt;
it takes 1140 ticks&lt;br /&gt;
&lt;br /&gt;
for n = 100000000&lt;br /&gt;
it takes 6031 ticks&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
there is a roughly linear corrolation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Task 2 ==&lt;br /&gt;
&lt;br /&gt;
changing the &amp;quot;* 2&amp;quot; to &amp;quot;* 10&amp;quot; yields the following resluts&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for n = 1000000&lt;br /&gt;
it takes 62 ticks&lt;br /&gt;
&lt;br /&gt;
for n = 10000000&lt;br /&gt;
it takes 468 ticks&lt;br /&gt;
&lt;br /&gt;
for n = 20000000&lt;br /&gt;
it takes 1062 ticks&lt;br /&gt;
&lt;br /&gt;
for n = 100000000&lt;br /&gt;
it takes 4921 ticks&lt;br /&gt;
&lt;br /&gt;
for n = 1000000000&lt;br /&gt;
it runs out of memory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This demonstrates that if we use a larger multiplier then as the array gets very large it is more efficent (ie: when we went to 100000000 repititions the program got considerably faster) but it also runs out of memory faster. The reason for this is that it is allocating considerably larger and larger chunks of memory each time therefor it does not need to reallocate memory as often, speeding up the process but it also reaches maximum memory much faster.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Task 3 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for ARRAYLIST_MIN_ALLOC = 16000&lt;br /&gt;
&lt;br /&gt;
The time speeds up slightly for smaller values but as we go higher the time taken is actually a little longer ( by about 50ticks)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Task 4 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
calling ensure_capacity speeds up the program very slightly, similar to increasing ARRAYLIST_MIN_ALLOC&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Task 5 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for n = 1000000&lt;br /&gt;
it takes 266 ticks&lt;br /&gt;
&lt;br /&gt;
for n = 10000000&lt;br /&gt;
it takes 21563 ticks&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This strategy is very fast for small arrays but as soon as we introduce larger arrays it becomes unsusable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Task 6 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Doing this takes forever! This is probably because the memory needs to be reallocated instead of just one character/integer being added to the end.&lt;br /&gt;
&lt;br /&gt;
== Sample Code ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;time.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;arraylist.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
int main (){&lt;br /&gt;
&lt;br /&gt;
    long start, stop;&lt;br /&gt;
    ArrayList AL;&lt;br /&gt;
    int n, i;&lt;br /&gt;
&lt;br /&gt;
    n = 10000;&lt;br /&gt;
    &lt;br /&gt;
    arraylist_init( &amp;amp;AL );&lt;br /&gt;
&lt;br /&gt;
    start = clock();&lt;br /&gt;
	for (i=0; i&amp;lt;n; i++){&lt;br /&gt;
	    arraylist_put(&amp;amp;AL, 1, 0);&lt;br /&gt;
	}&lt;br /&gt;
	stop  = clock();&lt;br /&gt;
    &lt;br /&gt;
	printf(&amp;quot;The time taken = %ld&amp;quot;, (stop - start));&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>