Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Components and RAM

Status
Not open for further replies.

Leroy1981

Programmer
Jul 22, 2002
46
US
i was wondering if anyone knew how much RAM c++ builder's components use. like for example if i was to add a TStaticText to my project, how much extra memory would be needed. also does anyone know much memory a TCustomControl
takes up?

Thanx in advance
 
Well, just a reminder : simple sizeof(xxx) is not going to be enough for every component! Some of them act as containers which means that there is a lot more of data allocated in memory then sizeof() can tell... :)
 
I agree with bNasty, what you can do to solve this "problem" is adding the sizes like this

Size1 = sizeof (TPanel);
Size1 = sizeof (TButton);
...
Sizen = sizeof (TEdit);
TotalSize = Size1 + Size2 + ... + Sizen;

But as you can see a Form is a container too, but it has a class and this class (TForm) has the all size for the unit (Window). So if you want to know the size of your unit (Window, Form) you just call the sizeof method like this

FormSize = sizeof (TName_of _the_form)

--- LastCyborg ---
 
Also remember that some containers contain pointers. A pointer says nothing about the size of the data it's pointing to. For instance, the following object would seem simple:

struct MyStruct
{
char x;
TList *List;
}mystruct;

It's size will only be...3 bytes I believe? I don't know how many bytes it takes to store a TList pointer, but it's small, you get the idea. The problem is that TList might contain a list of 1000000 strings or other objects.

Just out of curiousity, do you mind saying why you are concerned with memory on those components? They seem very insignificant for a windows program. I wouldn't think even the minimum PC with requirements for Win95 would have any problems with adding one of those.

Chris
 
Yes, Supernat03, that's exactly what what I meant to say with "containers" - you can never know (without looking at source code) how contained objects are stored inside contatiner! It is allways some kind of TList, or something similar, which is a small class, but dynamically allocates memory as the members are added.
And, TList* occupies 4 bytes (at least till we all have Opterons and 64-bit Windows :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top