Re: Memory (Structure vs Class)
- From: "Ralph" <nt_consulting64@xxxxxxxxx>
- Date: Wed, 29 Jul 2009 15:07:51 -0500
"David" <dw85745NOT@xxxxxxxxxxxxx> wrote in message
news:%23cSHWFIEKHA.3708@xxxxxxxxxxxxxxxxxxxxxxx
Thanks for the input Ralph. Helped clear up a few things
In VB objects can only be declared on the heap.
So, does the reference just reside on the heap or is the entire class
(property, methods, etc.) all on the heap?
[Note: what follows is a 10,000 foot view. There are chapters, articles, and
even whole books written on the subject.]
VB uses COM protocol for objects. Thus in VB an 'object reference' is
actually a reference to an Interface. It is a pointer to block of
information that is 16 or 32 bytes(?). (I think the later, but brain not
working at the moment. I'm sure someone will quickly correct me. ha)
With COM, components are published with an Interface - can be viewed as a
simple list of what is available - and then a coClass or actual object that
can service that interface.
So looking at the simple case of a local Class defined in VB.
Dim cls As Class1 ' this declares and defines a block of memory (that
16/32 byte thingy) that provides information on what kind of coClass is
needed.
It resides in the program text section or data section depending where used.
Set cls = New Class1
The object that is specificied in the reference is now created and a block
of memory which is essentially a vtable or struct containing the available
attributes or methods is created on the heap.
The code for this object is in the program text section and is only loaded
once or as needed, ie, if you have had 100 Class1 objects open - you would
have 100 blocks of the Class1 Interface reference info and Class1's private
data created on the heap - but that would be it.
Or look at it another way ...
Two classes (clsA and clsB) with identical interfaces and identical storage,
but clsA has very short methods with little code, while clsB has methods
that contain lines and lines of code.
With the exception that clsB methods may require more stack space for
automatic variables (when those methods are running/called). The 'heap' or
memory requirement would be identical.
If all on heap, ever run out of heap space?
Sure - even with VMM all memory is essentially limited at some point - to
the total ram and hd space available. Memory per se is seldom a problem with
the massive creation of VB objects. Usually a program or system runs out of
"resources" (file sizes, string sizes, GDIs, handles, etc.) long before it
ever actually runs out of "memory". The real problem is usually, because of
the redirected way VB manages objects, with it becoming horribly slow.
-ralph
.
- References:
- Memory (Structure vs Class)
- From: David
- Re: Memory (Structure vs Class)
- From: Ralph
- Re: Memory (Structure vs Class)
- From: David
- Re: Memory (Structure vs Class)
- From: Larry Serflaten
- Re: Memory (Structure vs Class)
- From: David
- Re: Memory (Structure vs Class)
- From: Ralph
- Re: Memory (Structure vs Class)
- From: David
- Memory (Structure vs Class)
- Prev by Date: Re: Integer or Long?
- Next by Date: Re: detect active state of network map and show it
- Previous by thread: Re: Memory (Structure vs Class)
- Next by thread: Re: Memory (Structure vs Class)
- Index(es):
Relevant Pages
|