1. Win32lib memory?/statement!
- Posted by Euman <euman at bellsouth.net> Jun 04, 2001
- 363 views
I was checking a few things out with win32lib recently and would like to know why for all the redundancy associated with most of the procedures..... for instance this little procedure: ---------------------------------------------------- procedure removeLVItem( integer iItem ) end if end for lvitem_data[iItem] = lvitem_BLANK lvitem_owner[iItem] = -1 if iItem = length(lvitem_data) then lvitem_data = lvitem_data[1 .. length(lvitem_data)-1] lvitem_owner = lvitem_owner[1 .. length(lvitem_owner)-1] end if end procedure Looks like if you have a slew of items in the LV that if you wanted to load some other data that you would be one by one freeing the memory for each item. I havent given this alot of time or thought but couldnt you globally track spent memory? and free only once. Euman
2. Re: Win32lib memory?/statement!
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 04, 2001
- 336 views
----- Original Message ----- From: "Euman" <euman at bellsouth.net> To: "EUforum" <EUforum at topica.com> Subject: Win32lib memory?/statement! > I was checking a few things out with win32lib > recently and would like to know why for > all the redundancy associated with most of the > procedures..... "most" of the procedures? Please define "most" for me. I used to think that it meant more than 50%. Is it true that more than 50% of all procedures in Win32lib.ew implement redundant code? I guess it also depends on your definition of redundant too. One definition I'd use is that redundant code is code that does nothing useful, either because some other code already did it or its effect has no effect on the program. > for instance this little procedure: > > lvitem_owner[iItem] = -1 > > if iItem = length(lvitem_data) then > lvitem_data = lvitem_data[1 .. length(lvitem_data)-1] > lvitem_owner = lvitem_owner[1 .. length(lvitem_owner)-1] > end if > end procedure > > Looks like if you have a slew of items in the LV that > if you wanted to load some other data that you > would be one by one freeing the memory for each item. I think what you saying is that ... "Looks like if you already have a slew of items in the LV and" "if you then wanted to load some other data that" "the library would be freeing the memory for each existing item" "one at a time". Well actually the code only frees the removed item if it happens to be the last item in the list. However there is redundant code in this example. If could have been coded as ... if iItem = length(lvitem_data) then -- Free up last item in list -- lvitem_data = lvitem_data[1 .. length(lvitem_data)-1] lvitem_owner = lvitem_owner[1 .. length(lvitem_owner)-1] else -- Mark this as a free item that can be reused. -- lvitem_data[iItem] = lvitem_BLANK lvitem_owner[iItem] = -1 end if > I havent given this alot of time or thought but couldnt > you globally track spent memory? and free only once. Sure. When would be a good moment to free it all up? ------ Derek Parnell Melbourne, Australia "To finish a job quickly, go slower."
3. Re: Win32lib memory?/statement!
- Posted by Euman <euman at bellsouth.net> Jun 04, 2001
- 354 views
> "most" of the procedures? Please define "most" for me. OK, ALL of win32lib is redundant! Just one of the millions hdc = getDC( Screen ) releaseDC( Screen ) if you want to show several images on screen why grab and release the ScreenDC everytime. When I said most I should have said ALL. I like win32lib dont get me wrong. > I used to think that > it meant more than 50%. Is it true that more than 50% of all procedures in > Win32lib.ew implement redundant code? YES > I guess it also depends on your > definition of redundant too. Beating a dead horse........ > One definition I'd use is that redundant code > is code that does nothing useful, either because some other code already did > it or its effect has no effect on the program. Yeah! > I think what you saying is that ... > > "Looks like if you already have a slew of items in the LV and" > "if you then wanted to load some other data that" > "the library would be freeing the memory for each existing item" > "one at a time". > In other words.... > Well actually the code only frees the removed item if it happens to be the > last item in the list. However there is redundant code in this example. It > could have been coded as ... > > > if iItem = length(lvitem_data) then > -- Free up last item in list -- > lvitem_data = lvitem_data[1 .. length(lvitem_data)-1] > lvitem_owner = lvitem_owner[1 .. length(lvitem_owner)-1] > else > -- Mark this as a free item that can be reused. -- > lvitem_data[iItem] = lvitem_BLANK > lvitem_owner[iItem] = -1 > end if > or when the LVItems are created return the address of the first item calculating consumption up to the end of the last item then free the space when not needed in one call to release_mem..... I think I'll try to code this and give it to you. > > I havent given this alot of time or thought but couldnt > > you globally track spent memory? and free only once. > > Sure. When would be a good moment to free it all up? > My opinion is if you want to use deleteItems with -1 this must mean that ALL of the items should go... Why call the same procedure as many times as you have Items in the list. duh I like you Derek only because I strive to be as smart as you......:) > ------ > Derek Parnell > Melbourne, Australia > "To finish a job quickly, go slower." Euman
4. Re: Win32lib memory?/statement!
- Posted by gertie at ad-tek.net Jun 05, 2001
- 356 views
On 5 Jun 2001, at 7:08, Derek Parnell wrote: > > I havent given this alot of time or thought but couldnt > > you globally track spent memory? and free only once. > > Sure. When would be a good moment to free it all up? function idle() for loop = 1 to length(varlist) do if var[idle] then free it end for end function -- idle() x = routine_id(idle) -- main code do things..... do_events() or sleep(0) -- and if no events in que, then we aren't busy doing something for User, so clean up after ourselves -- also.... ( mirc code to trigger the cleanup periodically .timer [ $+ [ cleanup ] ] 0 60 do_cleanup ) -- or ( if lots_on_"to_free"_list then do_cleanup ) do other things -- end program Kat
5. Re: Win32lib memory?/statement!
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 05, 2001
- 346 views
Thanks Kat. I'll see how this technique works in the library. ------ Derek Parnell Melbourne, Australia "To finish a job quickly, go slower." ----- Original Message ----- From: <gertie at ad-tek.net> To: "EUforum" <EUforum at topica.com> Subject: Re: Win32lib memory?/statement! > > > On 5 Jun 2001, at 7:08, Derek Parnell wrote: > > > > I havent given this alot of time or thought but couldnt > > > you globally track spent memory? and free only once. > > > > Sure. When would be a good moment to free it all up? > > function idle() > for loop = 1 to length(varlist) do > if var[idle] then free it > end for > end function -- idle() > > x = routine_id(idle) > > -- main code > do things..... > do_events() or sleep(0) -- and if no events in que, then we aren't busy doing something > for User, so clean up after ourselves > -- also.... > ( mirc code > to trigger the cleanup periodically > .timer [ $+ [ cleanup ] ] 0 60 do_cleanup > ) > -- or > ( if lots_on_"to_free"_list then do_cleanup ) > do other things > -- end program > > > Kat > > > >