Hi,


The "standard" way I would use to create a component instance is use cfobject. And then I'd use cfinvoke to call various methods of the component. Often the first cfinvoke is an init type of method.

If create an init method that will returns this, it seems to create a component instance in memory the same way that cfobject would. Is this what actually happens?

I attached a test component and the file I was using to test this. The tickcount wasn't much help since they were zero most of the time. The dump seemed to randomly change the order of methods in the component.


--
Jeffry Houser, Web Developer <mailto:[EMAIL PROTECTED]>
Aaron Skye, Guitarist / Songwriter <mailto:[EMAIL PROTECTED]>
--
AIM: Reboog711 | Phone: 1-203-379-0773
--
My Books: <http://www.instantcoldfusion.com>
Recording Music: <http://www.fcfstudios.com>
Original Energetic Acoustic Rock: <http://www.farcryfly.com>
<!--- www.instantcoldfusion.com

Description: a CFC to create a Stack
                        A stack is a specialized version of an array where elements 
can only be added or 
                        removed at the top of the array.
                        The methods to create the stack will be StackNew, StackPop, 
StackPush

Entering: N/A
Exiting: N/A

Dependencies: N/A
Expecting: N/A

Modification History
Date       Modifier                Modification
******************************************************
04/07/2002 Jeff Houser, DotComIt   Created
01/03/2003              Jeff Houser, DotComIt           Modified to store the Array as 
a private part of the component;
                                                                                       
                                                         No longer passing the stack 
in and out of the functions 
                                                                                       
                                                         The This Scope is public
                                                                                       
                                                         the unnamed scope is private 
--->

<cfcomponent output="false">

        <!--- Constructor Code to create a new stack --->
        <!--- a stack is a structure containing a 1 dimensional array --->
        <!--- This is so the stack methods can act as Array or Structure functions and 
the --->
        
<!--- 
        <cfset StackArray = ArrayNew(1)>
--->    

        <cffunction name="init" access="public">
                <cfset StackArray = ArrayNew(1)>
                <cfreturn this>
        </cffunction>

        <!--- a function to add an element onto the stack --->
        <!--- using the ArrayPrepend value --->
        <cffunction name="StackPush" access="public">
                <cfargument name="StackElement" required="Yes">
<!--- 
                <cfset this.item = ArrayPrepend(arguments.Stack.StackArray,  
arguments.StackElement)>
                <cfreturn this.item>
 --->
                <cfreturn ArrayPrepend(StackArray, arguments.StackElement)>
        </cffunction>

        <!--- a function to remove an element from the stack --->
        <!--- a stack is a 1 dimensional array --->
        <cffunction name="StackPop" access="public">
                <cfset var item = StackArray[1]>
                <cfset deleted = ArrayDeleteAt(StackArray, 1)>
                <cfreturn item>
        </cffunction>
        
        <!--- a function to return the length of the stack --->
        <!--- a stack is a 1 dimensional array --->
        <cffunction name="StackLength" access="public">
                <cfreturn ArrayLen(StackArray)>
        </cffunction>

        
</cfcomponent>
<cfset TicketOne = GetTickCount()>
<cfobject component="Stack" name="MyStackObject">
<cfset TicketTwo = GetTickCount()>


<cfinvoke component="stack" method="Init" returnvariable="MyStackInvoked">
<cfset TicketThree = GetTickCount()>


<cfoutput>
        Invoking via CFObject: #TicketTwo - TicketOne#<br><br>
        Invoking via cfinvoke: #TicketThree - TicketTwo#<br><br>
        
</cfoutput>

<cfdump var="#MyStackInvoked#">

<cfdump var="#MyStackObject#">

Reply via email to