<?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%3Assre005</id>
	<title>SE250:lab-3:ssre005 - 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%3Assre005"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:ssre005&amp;action=history"/>
	<updated>2026-04-28T21:02:27Z</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:ssre005&amp;diff=5880&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:ssre005&amp;diff=5880&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:30Z</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;1.&lt;br /&gt;
Original code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    int x = 1;&lt;br /&gt;
    int n  = 1000000;&lt;br /&gt;
    int i;&lt;br /&gt;
    long t, t1, addTime;&lt;br /&gt;
    &lt;br /&gt;
    ArrayList array;&lt;br /&gt;
    arraylist_init (&amp;amp;array);&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    t = clock();&lt;br /&gt;
&lt;br /&gt;
    for (i = 0; i &amp;lt; n; i++){&lt;br /&gt;
    arraylist_push ( &amp;amp;array, x );&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    t1 = clock();&lt;br /&gt;
&lt;br /&gt;
    addTime =(t1 - t);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;For no. of Insertions n = %d. taken for one element insertion is %ld / %d clocks&amp;quot;, n, addTime, n);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output was 0 for n = 10000.  Higher Values tried.&lt;br /&gt;
&lt;br /&gt;
For no. of Insertions n = 1000000. taken for one element insertion is 46 / 1000000 clocks&lt;br /&gt;
For no. of Insertions n = 10000000. taken for one element insertion is 437 / 10000000 clocks&lt;br /&gt;
For no. of Insertions n = 100000000. taken for one element insertion is 4040 / 100000000 clocks&lt;br /&gt;
For no. of Insertions n  = 1000000000; error shows up&lt;br /&gt;
&lt;br /&gt;
assertion &amp;quot;alist-&amp;gt;arr != (element_t*)0&amp;quot; failed: file &amp;quot;arraylist.c&amp;quot;, line 39&lt;br /&gt;
/usr/bin/bash: line 1:  4536 Hangup                  ./arraylist.exe&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2.&lt;br /&gt;
&lt;br /&gt;
Using *10 growth factor.&lt;br /&gt;
&lt;br /&gt;
For no. of Insertions n = 1000000. taken for one element insertion is 31 / 1000000 clocks&lt;br /&gt;
For no. of Insertions n = 10000000. taken for one element insertion is 343 / 10000000 clocks&lt;br /&gt;
For no. of Insertions n = 100000000. taken for one element insertion is 3447 / 100000000 clocks&lt;br /&gt;
For no. of Insertions n  = 1000000000; error shows up&lt;br /&gt;
&lt;br /&gt;
assertion &amp;quot;alist-&amp;gt;arr != (element_t*)0&amp;quot; failed: file &amp;quot;arraylist.c&amp;quot;, line 39&lt;br /&gt;
/usr/bin/bash: line 1:  4536 Hangup                  ./arraylist.exe&lt;br /&gt;
&lt;br /&gt;
Time taken reduces.&lt;br /&gt;
&lt;br /&gt;
Using +100 growth factor.&lt;br /&gt;
&lt;br /&gt;
For no. of Insertions n = 1000000. taken for one element insertion is 187 / 1000000 clocks&lt;br /&gt;
For no. of Insertions n = 10000000. taken for one element insertion is 19016 / 10000000 clocks&lt;br /&gt;
Anything else took way too long.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Multiplying by 2 allocates twice the existing memory allocation so  more insertions can occur without having to allocate more memory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3.&lt;br /&gt;
&lt;br /&gt;
Keeping n = 1000000 constant and changing the value of ARRAYLIST_MIN_ALLOC (original is 16) by a factor of 10.&lt;br /&gt;
&lt;br /&gt;
ARRAYLIST_MIN_ALLOC = 160&lt;br /&gt;
For no. of Insertions n = 1000000. taken for one element insertion is 31 / 1000000 clocks&lt;br /&gt;
&lt;br /&gt;
ARRAYLIST_MIN_ALLOC = 1600&lt;br /&gt;
For no. of Insertions n = 1000000. taken for one element insertion is 47 / 1000000 clocks&lt;br /&gt;
&lt;br /&gt;
ARRAYLIST_MIN_ALLOC = 16000&lt;br /&gt;
For no. of Insertions n = 1000000. taken for one element insertion is 31 / 1000000 clocks&lt;br /&gt;
&lt;br /&gt;
ARRAYLIST_MIN_ALLOC = 16000&lt;br /&gt;
For no. of Insertions n = 1000000. taken for one element insertion is 46 / 1000000 clocks&lt;br /&gt;
&lt;br /&gt;
ARRAYLIST_MIN_ALLOC = 160&lt;br /&gt;
For no. of Insertions n = 1000000. taken for one element insertion is 31 / 1000000 clocks&lt;br /&gt;
&lt;br /&gt;
Therefore, no significant changes.&lt;br /&gt;
&lt;br /&gt;
4.&lt;br /&gt;
&lt;br /&gt;
Adding ‘ensure_capacity(&amp;amp;array, 100000000000 );’ before the t = clock(); line and repeating the first experiment gives the following results:&lt;br /&gt;
&lt;br /&gt;
For no. of Insertions n = 1000000. taken for one element insertion is 46 / 1000000 clocks&lt;br /&gt;
For no. of Insertions n = 10000000. taken for one element insertion is 390 / 10000000 clocks&lt;br /&gt;
For no. of Insertions n = 100000000. taken for one element insertion is 3744 / 100000000 clocks&lt;br /&gt;
For no. of Insertions n = 1000000000. Error: /usr/bin/bash: line 1:  3944 Segmentation fault      (core dumped) ./arraylist.exe&lt;br /&gt;
&lt;br /&gt;
5.&lt;br /&gt;
&lt;br /&gt;
ALREADY DONE THAT NYA NYA NYA!!&lt;br /&gt;
&lt;br /&gt;
6.&lt;br /&gt;
&lt;br /&gt;
Changing  arraylist_push ( &amp;amp;array, x ); to arraylist_put ( &amp;amp;array, x , 0); and repeating experiment 1 gives the following results:&lt;br /&gt;
&lt;br /&gt;
Takes way too long to wait for.   Good explanation would be that to add something on to the start of a chunk of used memory (using arraylist_put), the entire used memory section must be shifted to make space for the new insertion whereas with arraylist_push, adding something to the end does not require any shifting of the used memory section.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>