My analogy goes as follows: a chunk of memory for temporary needs => scratch pad (as in sheet of paper for quick notes/sketches).

Something along the lines of:

class A{
        static float[] buffer;
        static this(){
                buffer = new float[as_big_as_it_gets];
        }

        void foo(){
                float[] tempAlloc = buffer[0..need_this_much];
                tempAlloc[] = 0.0;
                ...
        }       
}

As long as foo is not called recursively should just work. Other thing that may wreck this is if foo is called in Fiber context and uses yeild internally.

One may as well fall back to option 3 in rare cases where scratch pad is too small to fit the bill.

I really like the idea.
I've changed it a bit:
I have a float[1024] buffer which is used, as long as the requested size is less than 1024. If it's greater, I will temporary allocate the whole array with new float[Size];
Any improvements? Or is 1024 to small / big?

Reply via email to