Memory Issue... List Gadgets <_<

Just starting out? Need help? Post your questions and find answers here.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Here's a quick and dirty virtual ListIconGadget...

Code: Select all

;... Use 1000000 items 
#ItemCount = 1000000 

#LVSICF_NOINVALIDATEALL = 1 
#LVN_ODCACHEHINT = #LVN_FIRST - 13


;... Array to hold data 
Global Dim myItems.s(#ItemCount,1) 

Procedure WinCallback(hwnd, msg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_NOTIFY 
      *pnmh.NMHDR = lParam 
      Select *pnmh\code 
        Case #LVN_ODCACHEHINT 
          result = 0  
        Case #LVN_GETDISPINFO 
          *pnmlvdi.NMLVDISPINFO = lParam 
          If *pnmlvdi\item\mask & #LVIF_TEXT 
            ;... Item text is being requested 
            *pnmlvdi\item\pszText = @myItems(*pnmlvdi\item\iItem,*pnmlvdi\item\iSubItem) 
          EndIf 
          
      EndSelect 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

If OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@WinCallback()) 
  ; left column 
  list=ListIconGadget(#PB_Any,10,10,620,280,"ID",50,#LVS_OWNERDATA) 
  ;... Set desired number of ListIconGdaget items 
  SendMessage_(GadgetID(list), #LVM_SETITEMCOUNT, #ItemCount, #LVSICF_NOINVALIDATEALL) 
  AddGadgetColumn(list,2,"Name",100) 
  For i=0 To #ItemCount
    myItems(i,0) = Str(i)
    myItems(i,1) = "Name"+Str(i)
  Next i 
  ; Here we change the ListIcon display to large icons and show an image 
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf 
Last edited by Sparkie on Mon Dec 08, 2008 7:21 pm, edited 2 times in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I don't understand why you need the SetGadgetItemText()s Sparks?

Surely the whole point of a virtual control is that the callback supplies the text?
I may look like a mule, but I'm not a complete ass.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You're absolutely correct srod. That was the dirty of quick and dirty. :P

I've edited the original code and I thank you sir for your keen eye. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Sparkie wrote:You're absolutely correct srod. That was the dirty of quick and dirty. :P

I've edited the original code and I thank you sir for your keen eye. :)
:lol:

Aye, I am forever on the lookout for quick and dirty....... uhm, not sure that sounds right somehow? :)
I may look like a mule, but I'm not a complete ass.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Sounds about right for you my friend. :twisted: :wink:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Sparkie wrote:Sounds about right for you my friend. :twisted: :wink:
I agree! :)
I may look like a mule, but I'm not a complete ass.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

srod wrote: Aye, I am forever on the lookout for quick and dirty....... uhm, not sure that sounds right somehow? :)
Well, I dunno... sounds kinda' right to me :shock: :lol:
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

Thanks sparkie, I've been wondering about a virtual listview in PB. This reminded me and demo'd it all at once :)

An interesting article about virtual listview controls
http://blogs.msdn.com/cumgranosalis/arc ... Usage.aspx
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Very interesting. I had also seen your other post on virtual lists (Sparkie) and am considering using them in an app I have which needs to refresh a list of potententially many thousand items, which can be a little sluggish.

What are the downsides to virtual lists?

cheers
Post Reply