Big for large arrays!
I think if I was going to do something like this, I would implement a Round
Robin (roro) idea.
In other words:
<cfset myArray = Arraynew(1)>
<cfset nextIndexToFill = 1>
<cfset NextIndexToRetrieve = 1>
Code to add:
<cfset myArray[nextIndexToFill] = "Value">
<cfset nextIndexToFill = nextIndexToFill + 1>
Code to retrieve
<cfset myVar = myArray[nextIndexToRetrieve]>
<cfset nextIndexToRetrieve = nextIndexToRetrieve + 1>
If (for example) you didn't want the array to get larger than 100, you could
add in:
<cfif nextIndexToFill eq 100>
<cfset nextIndexToFill = 1>
</cfif>
And
<cfif nextIndexToRetrieve eq 100>
<cfset nextIndexToRetrieve = 1>
</cfif>
This way, you limit the storage mechanism (the array) to whatever size you
want. You also stop the looping (seen below) happening which can definitely
slow down the code if you have a large array.
Remember, though, that the application has to remember what the pointer to
the array index is pointing at.
HTH
Paul
> Try the following code...
>
> <cfset myArray = ArrayNew(1)>
>
> <cfset myArray[1] = "First In">
> <cfset myArray[2] = "Second In">
> <cfset myArray[3] = "Third In">
> <cfset myArray[4] = "Fourth In">
>
> <cfoutput>#ArrayLen(myArray)#</cfoutput>
>
> <cfloop from="1" to="#ArrayLen(myArray) - 1#" index="i">
> <cfset ArraySwap(myArray, i, i + 1)>
> </cfloop>
>
> <cfset myArray[ArrayLen(myArray)] = "New Value">
>
> <cfoutput>
> <cfloop from="1" to="#ArrayLen(myArray)#" index="j">
> #myArray[j]#<br>
> </cfloop>
> </cfoutput>
>
> Ade
>
> -----Original Message-----
> From: Justin MacCarthy [mailto:[EMAIL PROTECTED]
> Sent: 13 March 2003 13:59
> To: Cfuk
> Subject: [ cf-dev ] FIFO queue
>
>
> Hi
> Has anyone here tested the various methods of
> implimenting a First_in_first_out queue using a ColdFusion MX
> Array? What is the fastest way?
>
> Cheers
>
> Justin
>
>
> --
> ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/
>
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED] For human help, e-mail:
> [EMAIL PROTECTED]
>
> --
> ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/
>
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED] For human help, e-mail:
> [EMAIL PROTECTED]
>
--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]