<?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%3Ajsmi233</id>
	<title>SE250:lab-3:jsmi233 - 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%3Ajsmi233"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:jsmi233&amp;action=history"/>
	<updated>2026-04-25T11:55:39Z</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:jsmi233&amp;diff=5582&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:jsmi233&amp;diff=5582&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:21Z</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;
  int main() {&lt;br /&gt;
  &lt;br /&gt;
      int n[4] = {100, 10000, 1000000, 100000000};  &lt;br /&gt;
  &lt;br /&gt;
      double results[4];&lt;br /&gt;
  &lt;br /&gt;
    long timeStart, timeTaken;&lt;br /&gt;
  &lt;br /&gt;
    int i;&lt;br /&gt;
  &lt;br /&gt;
    long long j;&lt;br /&gt;
  &lt;br /&gt;
    ArrayList list;&lt;br /&gt;
  &lt;br /&gt;
    arraylist_init(&amp;amp;list);&lt;br /&gt;
  &lt;br /&gt;
    for (i = 0; i &amp;lt; 4; i++) {&lt;br /&gt;
  &lt;br /&gt;
  	timeStart = clock();&lt;br /&gt;
  &lt;br /&gt;
  	for (j = 0; j &amp;lt; n[i]; j++) {&lt;br /&gt;
  &lt;br /&gt;
  	    arraylist_push(&amp;amp;list, 4);&lt;br /&gt;
  &lt;br /&gt;
  	}&lt;br /&gt;
  &lt;br /&gt;
  	timeTaken = clock() - timeStart;&lt;br /&gt;
  &lt;br /&gt;
  	results[i] = timeTaken / CLOCKS_PER_SEC;&lt;br /&gt;
  &lt;br /&gt;
  	printf(&amp;quot;For n = %d, the time taken is %f\n&amp;quot;, n[i], results[i]);&lt;br /&gt;
  &lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      return 0;&lt;br /&gt;
  &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
My initial output reported that for n &amp;lt;= 1000000, the time taken is zero. So I chose some different n values:&lt;br /&gt;
&lt;br /&gt;
For n = 40000000, the time taken is 2.797000&lt;br /&gt;
&lt;br /&gt;
For n = 80000000, the time taken is 5.343000&lt;br /&gt;
&lt;br /&gt;
For n = 120000000, the time taken is 7.719000&lt;br /&gt;
&lt;br /&gt;
For n = 160000000, the excecution failed. As someone else pointed out, this is probably the program has run out of memory.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Task 2:&lt;br /&gt;
&lt;br /&gt;
Using policy: new capacity = alist-&amp;gt;capacity + ARRAYLIST_MIN_ALLOC&lt;br /&gt;
&lt;br /&gt;
This doesn’t work for the same values in that it takes an insanely!!!!!! Long time (more time than I’m going to bothered waiting).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So get some new n values again.&lt;br /&gt;
&lt;br /&gt;
For n = 1000000, the time taken is 0.297000&lt;br /&gt;
&lt;br /&gt;
For n = 2000000, the time taken is 1.046000&lt;br /&gt;
&lt;br /&gt;
For n = 4000000, the time taken is 3.656000&lt;br /&gt;
&lt;br /&gt;
For n = 8000000, the time taken is 13.781000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using policy: new capacity = alist-&amp;gt;capacity * alist-&amp;gt;capacity&lt;br /&gt;
&lt;br /&gt;
For n = 90000, the program crashes with a rather strange looking error: &lt;br /&gt;
&lt;br /&gt;
      6 [main] lab3 5724 _cygtls::handle_exceptions: Exception: STATUS_ACCESS_VIOLATION&lt;br /&gt;
&lt;br /&gt;
   2507 [main] lab3 5724 open_stackdumpfile: Dumping stack trace to lab3.exe.stackdump&lt;br /&gt;
&lt;br /&gt;
For n &amp;lt; 90000, the time taken is close to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Task 3:&lt;br /&gt;
&lt;br /&gt;
ARRAYLIST_MIN_ALLOC 64&lt;br /&gt;
&lt;br /&gt;
For n = 10000000, the time taken is 0.656000&lt;br /&gt;
&lt;br /&gt;
For n = 20000000, the time taken is 1.376000&lt;br /&gt;
&lt;br /&gt;
For n = 30000000, the time taken is 2.000000&lt;br /&gt;
&lt;br /&gt;
For n = 40000000, the time taken is 2.563000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#define ARRAYLIST_MIN_ALLOC 512&lt;br /&gt;
&lt;br /&gt;
For n = 10000000, the time taken is 0.641000&lt;br /&gt;
&lt;br /&gt;
For n = 20000000, the time taken is 1.313000&lt;br /&gt;
&lt;br /&gt;
For n = 30000000, the time taken is 1.812000&lt;br /&gt;
&lt;br /&gt;
For n = 40000000, the time taken is 2.875000&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
#define ARRAYLIST_MIN_ALLOC 4096&lt;br /&gt;
&lt;br /&gt;
For n = 10000000, the time taken is 0.594000&lt;br /&gt;
&lt;br /&gt;
For n = 20000000, the time taken is 1.328000&lt;br /&gt;
&lt;br /&gt;
For n = 30000000, the time taken is 2.016000&lt;br /&gt;
&lt;br /&gt;
For n = 40000000, the time taken is 2.640000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Changing this initial value seems to have no effect.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Task 4:&lt;br /&gt;
&lt;br /&gt;
For n = 40000000, the time taken is 2.235000&lt;br /&gt;
&lt;br /&gt;
For n = 80000000, the time taken is 4.500000&lt;br /&gt;
&lt;br /&gt;
For n = 120000000, the time taken is 6.327000&lt;br /&gt;
&lt;br /&gt;
For n = 160000000, the time taken is 8.422000&lt;br /&gt;
&lt;br /&gt;
The values are pretty similar to task 1, however n = 160000000 actually works, whereas in task 1 it failed. I think it is very surprising that the values are similar to task 1, I had expected this method to be much faster.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Task 5:&lt;br /&gt;
&lt;br /&gt;
I pretty much already tried this in task 2, and I found that this is slower than multiplying the capacity each time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Task 6:&lt;br /&gt;
&lt;br /&gt;
Using the same n values, this is taking too long! &lt;br /&gt;
&lt;br /&gt;
For n = 40000, the time taken is 0.765000&lt;br /&gt;
&lt;br /&gt;
For n = 80000, the time taken is 2.953000&lt;br /&gt;
&lt;br /&gt;
For n = 120000, the time taken is 6.141000&lt;br /&gt;
&lt;br /&gt;
For n = 160000, the time taken is 10.906000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is not surprising that this takes a lot longer, since on each put operation, it must move every other value that has already been inserted.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>