SE250:lab-3:hlin079

From Marks Wiki
Jump to navigation Jump to search

Task1

When I used “push” put 4 10s at the end of the memory the time it took was: Time=0.046 int n[4]={1000,1000,1000,1000}; time =0.062000

task2

Changing the growth factor to “+20” produced the following result: Time=0.297000 Changing the growth factor to “*3” produced the following result: Time=0.062000 Changing the growth factor to “*6” produced the following result: Time= 0.046000 Using a multiplicative growth factor means that a large amount of memory is allocated so that there is much space to be used in memory before the process repeats. However, using an additive growth factor means that a constant amount of memory is allocated each time more memory is needed, and thus, the memory reallocation process is repeated more times and thus, adding several values into an array takes much longer.

Task3

Changing ARRAYLIST_MIN_ALLOC to 100 as opposed to 16 returned the following value: Time=0.047000 Changing ARRAYLIST_MIN_ALLOC to 4 as opposed to 16 returned the following value: Time= 0.062000 Using a higher ARRAYLIST_MIN_ALLOC means that with each multiplicative memory allocation, a much larger amount of memory is allocated. Eg. Using ARRAYLIST_MIN_ALLOC = 4 means that once these 4 bytes are used, the multiplicative factor (of 2) is applied, and 8 extra bytes are allocated. Using ARRAYLIST_MIN_ALLOC = 100, however, means that once 100 bytes are used, an extra 200 bytes are allocated and thus, the reallocation process is used much less often.

Task4

When ensure_capacity was used with max expected size set to “1000000” the time returned was: 0.061000

Task5

When the growth factor was changed to +1000, the time taken was: 0.265000

Task6

Using arraylist_put with index 0 took very long to compile and run as moving the used amount of memory to put new values in at the start takes much longer than adding values to the end which requires no moving of used memory.