Using Lists as storage in contexts with state (for optimization)

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

Using Lists as storage in contexts with state (for optimization)

Batuhan Bozkurt
Hi all,

I always had hard time wrapping my head around functional programming concepts so here is my question:

From all the List/FastList/Array optimization tips I read from the mailing list and haxe website, I get the impression that Lists can be used in place of arrays in almost(?) all cases (but not necessarily with better performance). However I'm having hard time implementing things with Lists when any sort of external "state" comes into play.

Here is an example code:

class Something
{
        var curState : Float;
        var coll : Array<Float>;

        public function new()
        {
                curState = 0.0;
                coll = new Array();
                for(i in 0...1024) { coll.push(0.0); } //is it possible to zero-initialize an array?
        }

        public function process()
        {
                for(i in 0...1024)
                {
                        coll[i] = curState;
                        curState += 0.1;
                }
        }
}

Let's say I'm targeting the flash platform where array access is slow. Is it possible and beneficial to convert the coll Array here to a FastList? (according to my ghetto profiling with top, accessing an array with indexes do have a big impact on performance)

If so, how can I access the curState of my object instance from inside the mapping function for the List? As far as I can see, the local functions are declared as static, and I can't pass in a pointer to my instance when I use List mapping.

Is something like this simply not possible/not suitable for linked lists? My conclusion was that lists are simply not appropriate for such tasks, but when I read things like "using Lists instead of Arrays" like it is a trivial thing to do, I get confused. Not being able to use anything related to a "state" limits the use of Lists for me in a lot of ways. Maybe I'm just wrong... Anyhow.

Thanks for any input.

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

Re: Using Lists as storage in contexts with state (for optimization)

justin_mills
Batuhan

Lists are interesting but they seem harder to use than arrays and in
flash I think lists are slower so I am not really sure how much they are
actually really used?  Not sure if you saw one my early haxe flash
experiment/example http://haxe.org/byexample/lambda/flash9/map but it
shows some lamda use which may or may not be useful and is a bit of
fun.  Not sure if this is too low level example, did not really follow
your needs.

Cheers ;J



Le 04/02/2011 13:32, Batuhan Bozkurt a écrit :

> Hi all,
>
> I always had hard time wrapping my head around functional programming concepts so here is my question:
>
>  From all the List/FastList/Array optimization tips I read from the mailing list and haxe website, I get the impression that Lists can be used in place of arrays in almost(?) all cases (but not necessarily with better performance). However I'm having hard time implementing things with Lists when any sort of external "state" comes into play.
>
> Here is an example code:
>
> class Something
> {
> var curState : Float;
> var coll : Array<Float>;
>
> public function new()
> {
> curState = 0.0;
> coll = new Array();
> for(i in 0...1024) { coll.push(0.0); } //is it possible to zero-initialize an array?
> }
>
> public function process()
> {
> for(i in 0...1024)
> {
> coll[i] = curState;
> curState += 0.1;
> }
> }
> }
>
> Let's say I'm targeting the flash platform where array access is slow. Is it possible and beneficial to convert the coll Array here to a FastList? (according to my ghetto profiling with top, accessing an array with indexes do have a big impact on performance)
>
> If so, how can I access the curState of my object instance from inside the mapping function for the List? As far as I can see, the local functions are declared as static, and I can't pass in a pointer to my instance when I use List mapping.
>
> Is something like this simply not possible/not suitable for linked lists? My conclusion was that lists are simply not appropriate for such tasks, but when I read things like "using Lists instead of Arrays" like it is a trivial thing to do, I get confused. Not being able to use anything related to a "state" limits the use of Lists for me in a lot of ways. Maybe I'm just wrong... Anyhow.
>
> Thanks for any input.
>
> Best,
> Batuhan


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