Re: Memory allocation/deallocation
- Posted by euman at bellsouth.net Feb 17, 2002
- 483 views
From: "George Papadopoulos" <georgp at otenet.gr> >Hi Euman >Thanks for the long reply. >I prefer to use allocate(m) and free(m) because the interprenter >frees any allocated memory in the case the program fails. >Is there any possibility to live unfreed blocks? I assume your talking about the set of routines I posted. I have checked them out and feel satisfied they are as good or better in most cases than Euphoria's built-in's. >in the case the program fails Euphoria may not free either if the program fails. >Is there any possibility to live unfreed blocks? Its good practice when you allocate any significant amount, for instance long strings, that you free this space up (yourself) as soon as your done using it. The good news about one of the functions I posted is: global function myalloc(integer size) return c_func(xHeapAlloc,{pHeap,HEAP_ZERO_MEMORY,size}) end function You can do: junk = myalloc(size) this instead of: junk = allocate(size) mem_set(junk,0,size) using HEAP_ZERO_MEMORY automatically 0's mem and saves you a call to mem_set (less typing, faster execution) Consider this function: global function peek_zstring(atom lpzString) return mypeek({lpzString,c_func(xlstrlen,{lpzString})}) end function 100's of times faster than anyother peek_string routines in Euphoria because of xlstrlen being faster than length() in this particular case. There are some other advantages to them. . Euman >-George