Fastest way to clear Array<T>

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Fastest way to clear Array<T>

Dinko Pavicic
Hi all!

In Flash the fastest way to clear the array is  'array.length = 0;' but in haxe length in get only.
Is the splice function like this 'm_Data.splice(0, m_Data.length);' ok to use regarding the speed?

In flash splice is quite slow.


Many thanks in advance,
D.
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

Baluta Cristian
maybe asigning [ ]


On Wed, Aug 31, 2011 at 12:56 AM, Dinko Pavicic <[hidden email]> wrote:
Hi all!

In Flash the fastest way to clear the array is  'array.length = 0;' but in
haxe length in get only.
Is the splice function like this 'm_Data.splice(0, m_Data.length);' ok to
use regarding the speed?

In flash splice is quite slow.


Many thanks in advance,
D.


--
View this message in context: http://haxe.1354130.n2.nabble.com/Fastest-way-to-clear-Array-T-tp6744238p6744238.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org



--
Băluță Cristian
http://ralcr.com
http://imagin.ro

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

Justin Donaldson-3
Splice is best if you're saving a reference to that array elsewhere.  Otherwise, go with Baluta's array assignment recommendation.

Alternatively, you can make a small "using" function that gives you the speed boost:

    public static function clear(arr:Array<Dynamic>){
        #if (cpp||php)
           arr.splice(0,arr.length);          
        #else
           untyped arr.length = 0;
        #end
    }

That should work on all targets. I ran an extremely quick and dirty test... setting length to 0 was faster in every target I could get it to work on.  However, that trick is not possible on cpp/php.  CPP seems like it could have a trick... but php doesn't.  Maybe Hugh or Franco can give more information.

Also, here's another blog post on clearing flash arrays:
http://www.homecoded.com/blog-entry-136.html


Best,
-Justin

On Tue, Aug 30, 2011 at 8:31 PM, Baluta Cristian <[hidden email]> wrote:
maybe asigning [ ]


On Wed, Aug 31, 2011 at 12:56 AM, Dinko Pavicic <[hidden email]> wrote:
Hi all!

In Flash the fastest way to clear the array is  'array.length = 0;' but in
haxe length in get only.
Is the splice function like this 'm_Data.splice(0, m_Data.length);' ok to
use regarding the speed?

In flash splice is quite slow.


Many thanks in advance,
D.


--
View this message in context: http://haxe.1354130.n2.nabble.com/Fastest-way-to-clear-Array-T-tp6744238p6744238.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org



--
Băluță Cristian
http://ralcr.com
http://imagin.ro

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

go2ghana
On 31.08.2011 09:37, Justin Donaldson wrote:
> Splice is best if you're saving a reference to that array elsewhere.  
> Otherwise, go with Baluta's array assignment recommendation.
>
Can you explain why the assignment solution would not be usable if there
is a reference to the array?

Cordially,
Axel

> Alternatively, you can make a small "using" function that gives you
> the speed boost:
>
>     public static function clear(arr:Array<Dynamic>){
>         #if (cpp||php)
>            arr.splice(0,arr.length);
>         #else
>            untyped arr.length = 0;
>         #end
>     }
>
> That should work on all targets. I ran an extremely quick and dirty
> test... setting length to 0 was faster in every target I could get it
> to work on.  However, that trick is not possible on cpp/php.  CPP
> seems like it could have a trick... but php doesn't.  Maybe Hugh or
> Franco can give more information.
>
> Also, here's another blog post on clearing flash arrays:
> http://www.homecoded.com/blog-entry-136.html
>
>
> Best,
> -Justin
>
> On Tue, Aug 30, 2011 at 8:31 PM, Baluta Cristian
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     maybe asigning [ ]
>
>
>     On Wed, Aug 31, 2011 at 12:56 AM, Dinko Pavicic
>     <[hidden email] <mailto:[hidden email]>> wrote:
>
>         Hi all!
>
>         In Flash the fastest way to clear the array is  'array.length
>         = 0;' but in
>         haxe length in get only.
>         Is the splice function like this 'm_Data.splice(0,
>         m_Data.length);' ok to
>         use regarding the speed?
>
>         In flash splice is quite slow.
>
>
>         Many thanks in advance,
>         D.
>
>
>         --
>         View this message in context:
>         http://haxe.1354130.n2.nabble.com/Fastest-way-to-clear-Array-T-tp6744238p6744238.html
>         Sent from the Haxe mailing list archive at Nabble.com.
>
>         --
>         haXe - an open source web programming language
>         http://haxe.org
>
>
>
>
>     --
>     Băluță Cristian
>     http://ralcr.com
>     http://imagin.ro
>
>     --
>     haXe - an open source web programming language
>     http://haxe.org
>
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

bubblebenj
Because the old array and so its elements will not be destroyed by the garbage collector since there is still a reference to the array.

Ben

On Wed, Aug 31, 2011 at 1:58 PM, Axel Huizinga <[hidden email]> wrote:
On <a href="tel:31.08.2011%2009" value="+13108201109" target="_blank">31.08.2011 09:37, Justin Donaldson wrote:
Splice is best if you're saving a reference to that array elsewhere.  Otherwise, go with Baluta's array assignment recommendation.

Can you explain why the assignment solution would not be usable if there is a reference to the array?

Cordially,
Axel
Alternatively, you can make a small "using" function that gives you the speed boost:

   public static function clear(arr:Array<Dynamic>){
       #if (cpp||php)
          arr.splice(0,arr.length);
       #else
          untyped arr.length = 0;
       #end
   }

That should work on all targets. I ran an extremely quick and dirty test... setting length to 0 was faster in every target I could get it to work on.  However, that trick is not possible on cpp/php.  CPP seems like it could have a trick... but php doesn't.  Maybe Hugh or Franco can give more information.

Also, here's another blog post on clearing flash arrays:
http://www.homecoded.com/blog-entry-136.html


Best,
-Justin

On Tue, Aug 30, 2011 at 8:31 PM, Baluta Cristian <[hidden email] <mailto:[hidden email]>> wrote:

   maybe asigning [ ]


   On Wed, Aug 31, 2011 at 12:56 AM, Dinko Pavicic
   <[hidden email] <mailto:[hidden email]>> wrote:

       Hi all!

       In Flash the fastest way to clear the array is  'array.length
       = 0;' but in
       haxe length in get only.
       Is the splice function like this 'm_Data.splice(0,
       m_Data.length);' ok to
       use regarding the speed?

       In flash splice is quite slow.


       Many thanks in advance,
       D.


       --
       View this message in context:
       http://haxe.1354130.n2.nabble.com/Fastest-way-to-clear-Array-T-tp6744238p6744238.html
       Sent from the Haxe mailing list archive at Nabble.com.

       --
       haXe - an open source web programming language
       http://haxe.org




   --     Băluță Cristian
   http://ralcr.com
   http://imagin.ro

   --
   haXe - an open source web programming language
   http://haxe.org




--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

Viktor Hesselbom-2
In reply to this post by go2ghana
Well, you wouldn't be clearing the array those are referencing to. You would just create a new array that only one place points to. All those other variables would still reference the old array.

Oh god, I'm horrible at explaining code.

Btw, if we're talking performance, wouldn't setting that function to inline be even faster?

Best,
Viktor

2011/8/31 Axel Huizinga <[hidden email]>
On <a href="tel:31.08.2011%2009" value="+13108201109" target="_blank">31.08.2011 09:37, Justin Donaldson wrote:
Splice is best if you're saving a reference to that array elsewhere.  Otherwise, go with Baluta's array assignment recommendation.

Can you explain why the assignment solution would not be usable if there is a reference to the array?

Cordially,
Axel
Alternatively, you can make a small "using" function that gives you the speed boost:

   public static function clear(arr:Array<Dynamic>){
       #if (cpp||php)
          arr.splice(0,arr.length);
       #else
          untyped arr.length = 0;
       #end
   }

That should work on all targets. I ran an extremely quick and dirty test... setting length to 0 was faster in every target I could get it to work on.  However, that trick is not possible on cpp/php.  CPP seems like it could have a trick... but php doesn't.  Maybe Hugh or Franco can give more information.

Also, here's another blog post on clearing flash arrays:
http://www.homecoded.com/blog-entry-136.html


Best,
-Justin

On Tue, Aug 30, 2011 at 8:31 PM, Baluta Cristian <[hidden email] <mailto:[hidden email]>> wrote:

   maybe asigning [ ]


   On Wed, Aug 31, 2011 at 12:56 AM, Dinko Pavicic
   <[hidden email] <mailto:[hidden email]>> wrote:

       Hi all!

       In Flash the fastest way to clear the array is  'array.length
       = 0;' but in
       haxe length in get only.
       Is the splice function like this 'm_Data.splice(0,
       m_Data.length);' ok to
       use regarding the speed?

       In flash splice is quite slow.


       Many thanks in advance,
       D.


       --
       View this message in context:
       http://haxe.1354130.n2.nabble.com/Fastest-way-to-clear-Array-T-tp6744238p6744238.html
       Sent from the Haxe mailing list archive at Nabble.com.

       --
       haXe - an open source web programming language
       http://haxe.org




   --     Băluță Cristian
   http://ralcr.com
   http://imagin.ro

   --
   haXe - an open source web programming language
   http://haxe.org




--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

Baluta Cristian
An inlined function must have a return.

On Wed, Aug 31, 2011 at 6:25 PM, Viktor Hesselbom <[hidden email]> wrote:
Well, you wouldn't be clearing the array those are referencing to. You would just create a new array that only one place points to. All those other variables would still reference the old array.

Oh god, I'm horrible at explaining code.

Btw, if we're talking performance, wouldn't setting that function to inline be even faster?

Best,
Viktor


2011/8/31 Axel Huizinga <[hidden email]>
On <a href="tel:31.08.2011%2009" value="+13108201109" target="_blank">31.08.2011 09:37, Justin Donaldson wrote:
Splice is best if you're saving a reference to that array elsewhere.  Otherwise, go with Baluta's array assignment recommendation.

Can you explain why the assignment solution would not be usable if there is a reference to the array?

Cordially,
Axel
Alternatively, you can make a small "using" function that gives you the speed boost:

   public static function clear(arr:Array<Dynamic>){
       #if (cpp||php)
          arr.splice(0,arr.length);
       #else
          untyped arr.length = 0;
       #end
   }

That should work on all targets. I ran an extremely quick and dirty test... setting length to 0 was faster in every target I could get it to work on.  However, that trick is not possible on cpp/php.  CPP seems like it could have a trick... but php doesn't.  Maybe Hugh or Franco can give more information.

Also, here's another blog post on clearing flash arrays:
http://www.homecoded.com/blog-entry-136.html


Best,
-Justin

On Tue, Aug 30, 2011 at 8:31 PM, Baluta Cristian <[hidden email] <mailto:[hidden email]>> wrote:

   maybe asigning [ ]


   On Wed, Aug 31, 2011 at 12:56 AM, Dinko Pavicic
   <[hidden email] <mailto:[hidden email]>> wrote:

       Hi all!

       In Flash the fastest way to clear the array is  'array.length
       = 0;' but in
       haxe length in get only.
       Is the splice function like this 'm_Data.splice(0,
       m_Data.length);' ok to
       use regarding the speed?

       In flash splice is quite slow.


       Many thanks in advance,
       D.


       --
       View this message in context:
       http://haxe.1354130.n2.nabble.com/Fastest-way-to-clear-Array-T-tp6744238p6744238.html
       Sent from the Haxe mailing list archive at Nabble.com.

       --
       haXe - an open source web programming language
       http://haxe.org




   --     Băluță Cristian
   http://ralcr.com
   http://imagin.ro

   --
   haXe - an open source web programming language
   http://haxe.org




--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Băluță Cristian
http://ralcr.com
http://imagin.ro

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

Yanis Benson

Since when?

On 31 Aug 2011 21:41, "Baluta Cristian" <[hidden email]> wrote:
> An inlined function must have a return.
>
> On Wed, Aug 31, 2011 at 6:25 PM, Viktor Hesselbom
> <[hidden email]>wrote:
>
>> Well, you wouldn't be clearing the array those are referencing to. You
>> would just create a new array that only one place points to. All those other
>> variables would still reference the old array.
>>
>> Oh god, I'm horrible at explaining code.
>>
>> Btw, if we're talking performance, wouldn't setting that function to inline
>> be even faster?
>>
>> Best,
>> Viktor
>>
>>
>> 2011/8/31 Axel Huizinga <[hidden email]>
>>
>>> On 31.08.2011 09:37, Justin Donaldson wrote:
>>>
>>>> Splice is best if you're saving a reference to that array elsewhere.
>>>> Otherwise, go with Baluta's array assignment recommendation.
>>>>
>>>> Can you explain why the assignment solution would not be usable if there
>>> is a reference to the array?
>>>
>>> Cordially,
>>> Axel
>>>
>>>> Alternatively, you can make a small "using" function that gives you the
>>>> speed boost:
>>>>
>>>> public static function clear(arr:Array<Dynamic>){
>>>> #if (cpp||php)
>>>> arr.splice(0,arr.length);
>>>> #else
>>>> untyped arr.length = 0;
>>>> #end
>>>> }
>>>>
>>>> That should work on all targets. I ran an extremely quick and dirty
>>>> test... setting length to 0 was faster in every target I could get it to
>>>> work on. However, that trick is not possible on cpp/php. CPP seems like it
>>>> could have a trick... but php doesn't. Maybe Hugh or Franco can give more
>>>> information.
>>>>
>>>> Also, here's another blog post on clearing flash arrays:
>>>> http://www.homecoded.com/blog-**entry-136.html<http://www.homecoded.com/blog-entry-136.html>
>>>>
>>>>
>>>> Best,
>>>> -Justin
>>>>
>>>> On Tue, Aug 30, 2011 at 8:31 PM, Baluta Cristian <
>>>> [hidden email] <mailto:[hidden email]**com<[hidden email]>>>
>>>> wrote:
>>>>
>>>> maybe asigning [ ]
>>>>
>>>>
>>>> On Wed, Aug 31, 2011 at 12:56 AM, Dinko Pavicic
>>>> <[hidden email] <mailto:[hidden email]**com.hr<[hidden email]>>>
>>>> wrote:
>>>>
>>>> Hi all!
>>>>
>>>> In Flash the fastest way to clear the array is 'array.length
>>>> = 0;' but in
>>>> haxe length in get only.
>>>> Is the splice function like this 'm_Data.splice(0,
>>>> m_Data.length);' ok to
>>>> use regarding the speed?
>>>>
>>>> In flash splice is quite slow.
>>>>
>>>>
>>>> Many thanks in advance,
>>>> D.
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://haxe.1354130.n2.nabble.**com/Fastest-way-to-clear-**
>>>> Array-T-tp6744238p6744238.html<http://haxe.1354130.n2.nabble.com/Fastest-way-to-clear-Array-T-tp6744238p6744238.html>
>>>> Sent from the Haxe mailing list archive at Nabble.com.
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>>
>>>>
>>>>
>>>>
>>>> -- Băluță Cristian
>>>> http://ralcr.com
>>>> http://imagin.ro
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>>
>>>>
>>>>
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>>
>>
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>
>
>
> --
> Băluță Cristian
> http://ralcr.com
> http://imagin.ro

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

Baluta Cristian
Must come from something else that error in my past experience, i was living with this impression for some time. Sorry for the error.

On Wed, Aug 31, 2011 at 8:50 PM, Yanis Benson <[hidden email]> wrote:

Since when?

On 31 Aug 2011 21:41, "Baluta Cristian" <[hidden email]> wrote:
> An inlined function must have a return.
>
> On Wed, Aug 31, 2011 at 6:25 PM, Viktor Hesselbom
> <[hidden email]>wrote:
>
>> Well, you wouldn't be clearing the array those are referencing to. You
>> would just create a new array that only one place points to. All those other
>> variables would still reference the old array.
>>
>> Oh god, I'm horrible at explaining code.
>>
>> Btw, if we're talking performance, wouldn't setting that function to inline
>> be even faster?
>>
>> Best,
>> Viktor
>>
>>
>> 2011/8/31 Axel Huizinga <[hidden email]>
>>
>>> On 31.08.2011 09:37, Justin Donaldson wrote:
>>>
>>>> Splice is best if you're saving a reference to that array elsewhere.
>>>> Otherwise, go with Baluta's array assignment recommendation.
>>>>
>>>> Can you explain why the assignment solution would not be usable if there
>>> is a reference to the array?
>>>
>>> Cordially,
>>> Axel
>>>
>>>> Alternatively, you can make a small "using" function that gives you the
>>>> speed boost:
>>>>
>>>> public static function clear(arr:Array<Dynamic>){
>>>> #if (cpp||php)
>>>> arr.splice(0,arr.length);
>>>> #else
>>>> untyped arr.length = 0;
>>>> #end
>>>> }
>>>>
>>>> That should work on all targets. I ran an extremely quick and dirty
>>>> test... setting length to 0 was faster in every target I could get it to
>>>> work on. However, that trick is not possible on cpp/php. CPP seems like it
>>>> could have a trick... but php doesn't. Maybe Hugh or Franco can give more
>>>> information.
>>>>
>>>> Also, here's another blog post on clearing flash arrays:
>>>> http://www.homecoded.com/blog-**entry-136.html<http://www.homecoded.com/blog-entry-136.html>

>>>>
>>>>
>>>> Best,
>>>> -Justin
>>>>
>>>> On Tue, Aug 30, 2011 at 8:31 PM, Baluta Cristian <
>>>> [hidden email] <mailto:[hidden email]**com<[hidden email]>>>

>>>> wrote:
>>>>
>>>> maybe asigning [ ]
>>>>
>>>>
>>>> On Wed, Aug 31, 2011 at 12:56 AM, Dinko Pavicic
>>>> <[hidden email] <mailto:[hidden email]**com.hr<[hidden email]>>>

>>>> wrote:
>>>>
>>>> Hi all!
>>>>
>>>> In Flash the fastest way to clear the array is 'array.length
>>>> = 0;' but in
>>>> haxe length in get only.
>>>> Is the splice function like this 'm_Data.splice(0,
>>>> m_Data.length);' ok to
>>>> use regarding the speed?
>>>>
>>>> In flash splice is quite slow.
>>>>
>>>>
>>>> Many thanks in advance,
>>>> D.
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://haxe.1354130.n2.nabble.**com/Fastest-way-to-clear-**
>>>> Array-T-tp6744238p6744238.html<http://haxe.1354130.n2.nabble.com/Fastest-way-to-clear-Array-T-tp6744238p6744238.html>

>>>> Sent from the Haxe mailing list archive at Nabble.com.
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>>
>>>>
>>>>
>>>>
>>>> -- Băluță Cristian
>>>> http://ralcr.com
>>>> http://imagin.ro
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>>
>>>>
>>>>
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>>
>>
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>
>
>
> --
> Băluță Cristian
> http://ralcr.com
> http://imagin.ro

--
haXe - an open source web programming language
http://haxe.org



--
Băluță Cristian
http://ralcr.com
http://imagin.ro

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

singmajesty
No, there is some kind of restriction with inlining and return values ...  
right, you can't inline a function that has a return value, unless it is  
static, or something? I don't quite remember, but this came up last week


On Wed, 31 Aug 2011 21:59:22 -0700, Baluta Cristian  
<[hidden email]> wrote:

> Must come from something else that error in my past experience, i was  
> living
> with this impression for some time. Sorry for the error.
>
> On Wed, Aug 31, 2011 at 8:50 PM, Yanis Benson  
> <[hidden email]>wrote:
>
>> Since when?
>> On 31 Aug 2011 21:41, "Baluta Cristian" <[hidden email]> wrote:
>> > An inlined function must have a return.
>> >
>> > On Wed, Aug 31, 2011 at 6:25 PM, Viktor Hesselbom
>> > <[hidden email]>wrote:
>> >
>> >> Well, you wouldn't be clearing the array those are referencing to.  
>> You
>> >> would just create a new array that only one place points to. All  
>> those
>> other
>> >> variables would still reference the old array.
>> >>
>> >> Oh god, I'm horrible at explaining code.
>> >>
>> >> Btw, if we're talking performance, wouldn't setting that function to
>> inline
>> >> be even faster?
>> >>
>> >> Best,
>> >> Viktor
>> >>
>> >>
>> >> 2011/8/31 Axel Huizinga <[hidden email]>
>> >>
>> >>> On 31.08.2011 09:37, Justin Donaldson wrote:
>> >>>
>> >>>> Splice is best if you're saving a reference to that array  
>> elsewhere.
>> >>>> Otherwise, go with Baluta's array assignment recommendation.
>> >>>>
>> >>>> Can you explain why the assignment solution would not be usable if
>> there
>> >>> is a reference to the array?
>> >>>
>> >>> Cordially,
>> >>> Axel
>> >>>
>> >>>> Alternatively, you can make a small "using" function that gives you
>> the
>> >>>> speed boost:
>> >>>>
>> >>>> public static function clear(arr:Array<Dynamic>){
>> >>>> #if (cpp||php)
>> >>>> arr.splice(0,arr.length);
>> >>>> #else
>> >>>> untyped arr.length = 0;
>> >>>> #end
>> >>>> }
>> >>>>
>> >>>> That should work on all targets. I ran an extremely quick and dirty
>> >>>> test... setting length to 0 was faster in every target I could get  
>> it
>> to
>> >>>> work on. However, that trick is not possible on cpp/php. CPP seems
>> like it
>> >>>> could have a trick... but php doesn't. Maybe Hugh or Franco can  
>> give
>> more
>> >>>> information.
>> >>>>
>> >>>> Also, here's another blog post on clearing flash arrays:
>> >>>> http://www.homecoded.com/blog-**entry-136.html<
>> http://www.homecoded.com/blog-entry-136.html>
>>
>> >>>>
>> >>>>
>> >>>> Best,
>> >>>> -Justin
>> >>>>
>> >>>> On Tue, Aug 30, 2011 at 8:31 PM, Baluta Cristian <
>> >>>> [hidden email] <mailto:cristi.baluta@gmail.**com<
>> [hidden email]>>>
>>
>> >>>> wrote:
>> >>>>
>> >>>> maybe asigning [ ]
>> >>>>
>> >>>>
>> >>>> On Wed, Aug 31, 2011 at 12:56 AM, Dinko Pavicic
>> >>>> <[hidden email] <mailto:[hidden email]-**com.hr<
>> [hidden email]>>>
>>
>> >>>> wrote:
>> >>>>
>> >>>> Hi all!
>> >>>>
>> >>>> In Flash the fastest way to clear the array is 'array.length
>> >>>> = 0;' but in
>> >>>> haxe length in get only.
>> >>>> Is the splice function like this 'm_Data.splice(0,
>> >>>> m_Data.length);' ok to
>> >>>> use regarding the speed?
>> >>>>
>> >>>> In flash splice is quite slow.
>> >>>>
>> >>>>
>> >>>> Many thanks in advance,
>> >>>> D.
>> >>>>
>> >>>>
>> >>>> --
>> >>>> View this message in context:
>> >>>> http://haxe.1354130.n2.nabble.**com/Fastest-way-to-clear-**
>> >>>> Array-T-tp6744238p6744238.html<
>> http://haxe.1354130.n2.nabble.com/Fastest-way-to-clear-Array-T-tp6744238p6744238.html
>> >
>>
>> >>>> Sent from the Haxe mailing list archive at Nabble.com.
>> >>>>
>> >>>> --
>> >>>> haXe - an open source web programming language
>> >>>> http://haxe.org
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>> -- Băluță Cristian
>> >>>> http://ralcr.com
>> >>>> http://imagin.ro
>> >>>>
>> >>>> --
>> >>>> haXe - an open source web programming language
>> >>>> http://haxe.org
>> >>>>
>> >>>>
>> >>>>
>> >>>
>> >>> --
>> >>> haXe - an open source web programming language
>> >>> http://haxe.org
>> >>>
>> >>
>> >>
>> >> --
>> >> haXe - an open source web programming language
>> >> http://haxe.org
>> >>
>> >
>> >
>> >
>> > --
>> > Băluță Cristian
>> > http://ralcr.com
>> > http://imagin.ro
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>
>
>


--
Using Opera's revolutionary email client: http://www.opera.com/mail/

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

Bruno Garcia-2
That doesn't sound right either, getters are definitely inlinable.

The only restriction I know of is that inline functions can't reference
an argument more than once. But even then, it'll still compile and run
just fine, it just won't be inlined.

Bruno

On 08/31/2011 10:36 PM, Joshua Granick wrote:

> No, there is some kind of restriction with inlining and return values
> ... right, you can't inline a function that has a return value, unless
> it is static, or something? I don't quite remember, but this came up
> last week
>
>
> On Wed, 31 Aug 2011 21:59:22 -0700, Baluta Cristian
> <[hidden email]> wrote:
>
>> Must come from something else that error in my past experience, i was
>> living
>> with this impression for some time. Sorry for the error.
>>
>> On Wed, Aug 31, 2011 at 8:50 PM, Yanis Benson
>> <[hidden email]>wrote:
>>
>>> Since when?
>>> On 31 Aug 2011 21:41, "Baluta Cristian" <[hidden email]>
>>> wrote:
>>> > An inlined function must have a return.
>>> >
>>> > On Wed, Aug 31, 2011 at 6:25 PM, Viktor Hesselbom
>>> > <[hidden email]>wrote:
>>> >
>>> >> Well, you wouldn't be clearing the array those are referencing
>>> to. You
>>> >> would just create a new array that only one place points to. All
>>> those
>>> other
>>> >> variables would still reference the old array.
>>> >>
>>> >> Oh god, I'm horrible at explaining code.
>>> >>
>>> >> Btw, if we're talking performance, wouldn't setting that function to
>>> inline
>>> >> be even faster?
>>> >>
>>> >> Best,
>>> >> Viktor
>>> >>
>>> >>
>>> >> 2011/8/31 Axel Huizinga <[hidden email]>
>>> >>
>>> >>> On 31.08.2011 09:37, Justin Donaldson wrote:
>>> >>>
>>> >>>> Splice is best if you're saving a reference to that array
>>> elsewhere.
>>> >>>> Otherwise, go with Baluta's array assignment recommendation.
>>> >>>>
>>> >>>> Can you explain why the assignment solution would not be usable if
>>> there
>>> >>> is a reference to the array?
>>> >>>
>>> >>> Cordially,
>>> >>> Axel
>>> >>>
>>> >>>> Alternatively, you can make a small "using" function that gives
>>> you
>>> the
>>> >>>> speed boost:
>>> >>>>
>>> >>>> public static function clear(arr:Array<Dynamic>){
>>> >>>> #if (cpp||php)
>>> >>>> arr.splice(0,arr.length);
>>> >>>> #else
>>> >>>> untyped arr.length = 0;
>>> >>>> #end
>>> >>>> }
>>> >>>>
>>> >>>> That should work on all targets. I ran an extremely quick and
>>> dirty
>>> >>>> test... setting length to 0 was faster in every target I could
>>> get it
>>> to
>>> >>>> work on. However, that trick is not possible on cpp/php. CPP seems
>>> like it
>>> >>>> could have a trick... but php doesn't. Maybe Hugh or Franco can
>>> give
>>> more
>>> >>>> information.
>>> >>>>
>>> >>>> Also, here's another blog post on clearing flash arrays:
>>> >>>> http://www.homecoded.com/blog-**entry-136.html<
>>> http://www.homecoded.com/blog-entry-136.html>
>>>
>>> >>>>
>>> >>>>
>>> >>>> Best,
>>> >>>> -Justin
>>> >>>>
>>> >>>> On Tue, Aug 30, 2011 at 8:31 PM, Baluta Cristian <
>>> >>>> [hidden email] <mailto:cristi.baluta@gmail.**com<
>>> [hidden email]>>>
>>>
>>> >>>> wrote:
>>> >>>>
>>> >>>> maybe asigning [ ]
>>> >>>>
>>> >>>>
>>> >>>> On Wed, Aug 31, 2011 at 12:56 AM, Dinko Pavicic
>>> >>>> <[hidden email] <mailto:[hidden email]-**com.hr<
>>> [hidden email]>>>
>>>
>>> >>>> wrote:
>>> >>>>
>>> >>>> Hi all!
>>> >>>>
>>> >>>> In Flash the fastest way to clear the array is 'array.length
>>> >>>> = 0;' but in
>>> >>>> haxe length in get only.
>>> >>>> Is the splice function like this 'm_Data.splice(0,
>>> >>>> m_Data.length);' ok to
>>> >>>> use regarding the speed?
>>> >>>>
>>> >>>> In flash splice is quite slow.
>>> >>>>
>>> >>>>
>>> >>>> Many thanks in advance,
>>> >>>> D.
>>> >>>>
>>> >>>>
>>> >>>> --
>>> >>>> View this message in context:
>>> >>>> http://haxe.1354130.n2.nabble.**com/Fastest-way-to-clear-**
>>> >>>> Array-T-tp6744238p6744238.html<
>>> http://haxe.1354130.n2.nabble.com/Fastest-way-to-clear-Array-T-tp6744238p6744238.html 
>>>
>>> >
>>>
>>> >>>> Sent from the Haxe mailing list archive at Nabble.com.
>>> >>>>
>>> >>>> --
>>> >>>> haXe - an open source web programming language
>>> >>>> http://haxe.org
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>> -- Băluță Cristian
>>> >>>> http://ralcr.com
>>> >>>> http://imagin.ro
>>> >>>>
>>> >>>> --
>>> >>>> haXe - an open source web programming language
>>> >>>> http://haxe.org
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>
>>> >>> --
>>> >>> haXe - an open source web programming language
>>> >>> http://haxe.org
>>> >>>
>>> >>
>>> >>
>>> >> --
>>> >> haXe - an open source web programming language
>>> >> http://haxe.org
>>> >>
>>> >
>>> >
>>> >
>>> > --
>>> > Băluță Cristian
>>> > http://ralcr.com
>>> > http://imagin.ro
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>>
>>
>>
>>
>
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

Alan Shaw-4
http://haxe.org/ref/inline If the function returns a value it can't have an early return.

-A


On Wed, Aug 31, 2011 at 10:48 PM, Bruno Garcia <[hidden email]> wrote:
That doesn't sound right either, getters are definitely inlinable.

The only restriction I know of is that inline functions can't reference an argument more than once. But even then, it'll still compile and run just fine, it just won't be inlined.

Bruno


On 08/31/2011 10:36 PM, Joshua Granick wrote:
No, there is some kind of restriction with inlining and return values ... right, you can't inline a function that has a return value, unless it is static, or something? I don't quite remember, but this came up last week


On Wed, 31 Aug 2011 21:59:22 -0700, Baluta Cristian <[hidden email]> wrote:

Must come from something else that error in my past experience, i was living
with this impression for some time. Sorry for the error.

On Wed, Aug 31, 2011 at 8:50 PM, Yanis Benson <[hidden email]>wrote:

Since when?
On 31 Aug 2011 21:41, "Baluta Cristian" <[hidden email]> wrote:
> An inlined function must have a return.
>
> On Wed, Aug 31, 2011 at 6:25 PM, Viktor Hesselbom
> <[hidden email]>wrote:
>
>> Well, you wouldn't be clearing the array those are referencing to. You
>> would just create a new array that only one place points to. All those
other
>> variables would still reference the old array.
>>
>> Oh god, I'm horrible at explaining code.
>>
>> Btw, if we're talking performance, wouldn't setting that function to
inline
>> be even faster?
>>
>> Best,
>> Viktor
>>
>>
>> 2011/8/31 Axel Huizinga <[hidden email]>
>>
>>> On <a href="tel:31.08.2011%2009" value="+13108201109" target="_blank">31.08.2011 09:37, Justin Donaldson wrote:
>>>
>>>> Splice is best if you're saving a reference to that array elsewhere.
>>>> Otherwise, go with Baluta's array assignment recommendation.
>>>>
>>>> Can you explain why the assignment solution would not be usable if
there
>>> is a reference to the array?
>>>
>>> Cordially,
>>> Axel
>>>
>>>> Alternatively, you can make a small "using" function that gives you
the
>>>> speed boost:
>>>>
>>>> public static function clear(arr:Array<Dynamic>){
>>>> #if (cpp||php)
>>>> arr.splice(0,arr.length);
>>>> #else
>>>> untyped arr.length = 0;
>>>> #end
>>>> }
>>>>
>>>> That should work on all targets. I ran an extremely quick and dirty
>>>> test... setting length to 0 was faster in every target I could get it
to
>>>> work on. However, that trick is not possible on cpp/php. CPP seems
like it
>>>> could have a trick... but php doesn't. Maybe Hugh or Franco can give
more
>>>> information.
>>>>
>>>> Also, here's another blog post on clearing flash arrays:
>>>> http://www.homecoded.com/blog-**entry-136.html<
http://www.homecoded.com/blog-entry-136.html>

>>>>
>>>>
>>>> Best,
>>>> -Justin
>>>>
>>>> On Tue, Aug 30, 2011 at 8:31 PM, Baluta Cristian <
>>>> [hidden email] <mailto:[hidden email]**com<
[hidden email]>>>

>>>> wrote:
>>>>
>>>> maybe asigning [ ]
>>>>
>>>>
>>>> On Wed, Aug 31, 2011 at 12:56 AM, Dinko Pavicic
>>>> <[hidden email] <mailto:[hidden email]**com.hr<
[hidden email]>>>

>>>> wrote:
>>>>
>>>> Hi all!
>>>>
>>>> In Flash the fastest way to clear the array is 'array.length
>>>> = 0;' but in
>>>> haxe length in get only.
>>>> Is the splice function like this 'm_Data.splice(0,
>>>> m_Data.length);' ok to
>>>> use regarding the speed?
>>>>
>>>> In flash splice is quite slow.
>>>>
>>>>
>>>> Many thanks in advance,
>>>> D.
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://haxe.1354130.n2.nabble.**com/Fastest-way-to-clear-**
>>>> Array-T-tp6744238p6744238.html<
http://haxe.1354130.n2.nabble.com/Fastest-way-to-clear-Array-T-tp6744238p6744238.html
>

>>>> Sent from the Haxe mailing list archive at Nabble.com.
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>>
>>>>
>>>>
>>>>
>>>> -- Băluță Cristian
>>>> http://ralcr.com
>>>> http://imagin.ro
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>>
>>>>
>>>>
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>>
>>
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>
>
>
> --
> Băluță Cristian
> http://ralcr.com
> http://imagin.ro

--
haXe - an open source web programming language
http://haxe.org








--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

Yanis Benson
In reply to this post by Bruno Garcia-2

It will be inlined. It will just create a local variable for that. I heard there is some weirdness on js taget though.

On 1 Sep 2011 09:50, "Bruno Garcia" <[hidden email]> wrote:
> That doesn't sound right either, getters are definitely inlinable.
>
> The only restriction I know of is that inline functions can't reference
> an argument more than once. But even then, it'll still compile and run
> just fine, it just won't be inlined.
>
> Bruno
>
> On 08/31/2011 10:36 PM, Joshua Granick wrote:
>> No, there is some kind of restriction with inlining and return values
>> ... right, you can't inline a function that has a return value, unless
>> it is static, or something? I don't quite remember, but this came up
>> last week
>>
>>
>> On Wed, 31 Aug 2011 21:59:22 -0700, Baluta Cristian
>> <[hidden email]> wrote:
>>
>>> Must come from something else that error in my past experience, i was
>>> living
>>> with this impression for some time. Sorry for the error.
>>>
>>> On Wed, Aug 31, 2011 at 8:50 PM, Yanis Benson
>>> <[hidden email]>wrote:
>>>
>>>> Since when?
>>>> On 31 Aug 2011 21:41, "Baluta Cristian" <[hidden email]>
>>>> wrote:
>>>> > An inlined function must have a return.
>>>> >
>>>> > On Wed, Aug 31, 2011 at 6:25 PM, Viktor Hesselbom
>>>> > <[hidden email]>wrote:
>>>> >
>>>> >> Well, you wouldn't be clearing the array those are referencing
>>>> to. You
>>>> >> would just create a new array that only one place points to. All
>>>> those
>>>> other
>>>> >> variables would still reference the old array.
>>>> >>
>>>> >> Oh god, I'm horrible at explaining code.
>>>> >>
>>>> >> Btw, if we're talking performance, wouldn't setting that function to
>>>> inline
>>>> >> be even faster?
>>>> >>
>>>> >> Best,
>>>> >> Viktor
>>>> >>
>>>> >>
>>>> >> 2011/8/31 Axel Huizinga <[hidden email]>
>>>> >>
>>>> >>> On 31.08.2011 09:37, Justin Donaldson wrote:
>>>> >>>
>>>> >>>> Splice is best if you're saving a reference to that array
>>>> elsewhere.
>>>> >>>> Otherwise, go with Baluta's array assignment recommendation.
>>>> >>>>
>>>> >>>> Can you explain why the assignment solution would not be usable if
>>>> there
>>>> >>> is a reference to the array?
>>>> >>>
>>>> >>> Cordially,
>>>> >>> Axel
>>>> >>>
>>>> >>>> Alternatively, you can make a small "using" function that gives
>>>> you
>>>> the
>>>> >>>> speed boost:
>>>> >>>>
>>>> >>>> public static function clear(arr:Array<Dynamic>){
>>>> >>>> #if (cpp||php)
>>>> >>>> arr.splice(0,arr.length);
>>>> >>>> #else
>>>> >>>> untyped arr.length = 0;
>>>> >>>> #end
>>>> >>>> }
>>>> >>>>
>>>> >>>> That should work on all targets. I ran an extremely quick and
>>>> dirty
>>>> >>>> test... setting length to 0 was faster in every target I could
>>>> get it
>>>> to
>>>> >>>> work on. However, that trick is not possible on cpp/php. CPP seems
>>>> like it
>>>> >>>> could have a trick... but php doesn't. Maybe Hugh or Franco can
>>>> give
>>>> more
>>>> >>>> information.
>>>> >>>>
>>>> >>>> Also, here's another blog post on clearing flash arrays:
>>>> >>>> http://www.homecoded.com/blog-**entry-136.html<
>>>> http://www.homecoded.com/blog-entry-136.html>
>>>>
>>>> >>>>
>>>> >>>>
>>>> >>>> Best,
>>>> >>>> -Justin
>>>> >>>>
>>>> >>>> On Tue, Aug 30, 2011 at 8:31 PM, Baluta Cristian <
>>>> >>>> [hidden email] <mailto:[hidden email]**com<
>>>> [hidden email]>>>
>>>>
>>>> >>>> wrote:
>>>> >>>>
>>>> >>>> maybe asigning [ ]
>>>> >>>>
>>>> >>>>
>>>> >>>> On Wed, Aug 31, 2011 at 12:56 AM, Dinko Pavicic
>>>> >>>> <[hidden email] <mailto:[hidden email]**com.hr<
>>>> [hidden email]>>>
>>>>
>>>> >>>> wrote:
>>>> >>>>
>>>> >>>> Hi all!
>>>> >>>>
>>>> >>>> In Flash the fastest way to clear the array is 'array.length
>>>> >>>> = 0;' but in
>>>> >>>> haxe length in get only.
>>>> >>>> Is the splice function like this 'm_Data.splice(0,
>>>> >>>> m_Data.length);' ok to
>>>> >>>> use regarding the speed?
>>>> >>>>
>>>> >>>> In flash splice is quite slow.
>>>> >>>>
>>>> >>>>
>>>> >>>> Many thanks in advance,
>>>> >>>> D.
>>>> >>>>
>>>> >>>>
>>>> >>>> --
>>>> >>>> View this message in context:
>>>> >>>> http://haxe.1354130.n2.nabble.**com/Fastest-way-to-clear-**
>>>> >>>> Array-T-tp6744238p6744238.html<
>>>> http://haxe.1354130.n2.nabble.com/Fastest-way-to-clear-Array-T-tp6744238p6744238.html
>>>>
>>>> >
>>>>
>>>> >>>> Sent from the Haxe mailing list archive at Nabble.com.
>>>> >>>>
>>>> >>>> --
>>>> >>>> haXe - an open source web programming language
>>>> >>>> http://haxe.org
>>>> >>>>
>>>> >>>>
>>>> >>>>
>>>> >>>>
>>>> >>>> -- Băluță Cristian
>>>> >>>> http://ralcr.com
>>>> >>>> http://imagin.ro
>>>> >>>>
>>>> >>>> --
>>>> >>>> haXe - an open source web programming language
>>>> >>>> http://haxe.org
>>>> >>>>
>>>> >>>>
>>>> >>>>
>>>> >>>
>>>> >>> --
>>>> >>> haXe - an open source web programming language
>>>> >>> http://haxe.org
>>>> >>>
>>>> >>
>>>> >>
>>>> >> --
>>>> >> haXe - an open source web programming language
>>>> >> http://haxe.org
>>>> >>
>>>> >
>>>> >
>>>> >
>>>> > --
>>>> > Băluță Cristian
>>>> > http://ralcr.com
>>>> > http://imagin.ro
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org

>>>>
>>>
>>>
>>>
>>
>>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Fastest way to clear Array<T>

Dinko Pavicic
Thanks you all for the tips!