Board index » cppbuilder » Items count

Items count


2005-10-06 06:11:48 PM
cppbuilder0
Hello.
Recently i've run into a problem - i have a ListView component on the main
form which is designated to show something around 1500 records (items).
These records i read from file using TFileStream class and save them to
TList.( Each TList item is a pointer to a struct.)
After this i add items to ListView and put the captions accordingly to a
TList structures. Everything works great. But when i Close the form - after
all the memory i use have released - i get acces violation within
inline __fastcall virtual ~TForm(void) { }.
Just curious - are there any limitations for the Tlist'Count property and
ListView'->Items->Count property?
 
 

Re:Items count

Not as far as I know.
It's more likely that you are deleting something explicitly in the
destructor
that has already been deleted by the form.
Note that controls that are 'owned' by the form get automatically
deleted by the form when destructor is called. So all ListView items
get deleted by the form.
If this doesn't help it would be worth showing a simplified version
of your code here so that we can help more.
HTH Pete
"Andrew Fedoseev" < XXXX@XXXXX.COM >wrote in message
Quote
Hello.
Recently i've run into a problem - i have a ListView component on the main
form which is designated to show something around 1500 records (items).
These records i read from file using TFileStream class and save them to
TList.( Each TList item is a pointer to a struct.)
After this i add items to ListView and put the captions accordingly to a
TList structures. Everything works great. But when i Close the form -
after
all the memory i use have released - i get acces violation within
inline __fastcall virtual ~TForm(void) { }.
Just curious - are there any limitations for the Tlist'Count property and
ListView'->Items->Count property?


 

Re:Items count

"Andrew Fedoseev" < XXXX@XXXXX.COM >wrote:
Quote

[...] designated to show something around 1500 records
Have you considered a virtual list view?
Quote
[...] when i Close the form - after all the memory i use
have released - i get acces violation within

inline __fastcall virtual ~TForm(void) { }.
I see that from time to time when I destruct something
incorrectly. I would suggest that you post your creation
code, where your adding, and your destruction code.
Quote
[...] are there any limitations for the Tlist'Count property
and ListView'->Items->Count property?
Yes. Both are int's so they are limited by the maximum number supported by 32 bits. That's about 4 billion.
~ JD
 

{smallsort}

Re:Items count

"Pete Fraser" < XXXX@XXXXX.COM >wrote:
Quote

[...] It's more likely that you are deleting something
explicitly in the destructor that has already been deleted
by the form.
That would be the other way around. The form cleans up it's
owned objects after the destructor executes.
~ JD
 

Re:Items count

"Andrew Fedoseev" < XXXX@XXXXX.COM >wrote in message
Quote
i have a ListView component on the main form which is designated
to show something around 1500 records (items). These records i
read from file using TFileStream class and save them to TList.( Each
TList item is a pointer to a struct.) After this i add items to ListView
and put the captions accordingly to a TList structures.
For that many items, and especially since you already have the struct data
stored in memory, you should be using the ListView in virtual mode
(OwnerData property is set to true and you have an OnData event handler), if
you are not already. There is no need to duplicate the data in the
ListView, and thus use twice as much memory, when it can use your existing
TList data memory directly. For example:
TList *MyList;
void __fastcall TForm1::LoadFile()
{
// make sure OwnerData=true beforehand ...
// open file, fill in TList as needed, then...
ListView1->Items->Count = MyList->Count;
}
void __fastcall TForm1::ListView1Data(TObject *Sender, TListItem *Item)
{
MyStruct *S = (MyStruct*) MyList->Items[Item->Index];
Item->Caption = S->Whatever;
// fill in other TListItem properties as needed...
}
Quote
But when i Close the form - after all the memory i use have released -
i get acces violation within inline __fastcall virtual ~TForm(void) { }.
Something is probably trying to access your memory after you have freed it.
Quote
Just curious - are there any limitations for the Tlist'Count property
TList is limited only by available memory.
Quote
and ListView'->Items->Count property?
If you are not using the ListView in virtual mode, then the ListView has
limited memory available for its items. 1500 is a lot of items for a
ListView to manage.
Gambit
 

Re:Items count

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
Both are int's so they are limited by the maximum number supported
by 32 bits. That's about 4 billion.
'int' is a signed type, not unsigned. The maximum value an 'int' can hold
is ~2 billion.
Even then, unless you have several GB of RAM installed (most people don't
even have 1GB installed), there is no way TList or TListView can hold 2
billion items at a time. That would require too much memory to be allocated
at one time. Even with 4+GB of RAM installed, the OS may not allow the
application to allocate that much memory at one time anyway.
Gambit