Re: Memory (Structure vs Class)

Tech-Archive recommends: Fix windows errors by optimizing your registry




"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



.



Relevant Pages

  • Re: to dispose or not ?
    ... always have the system memory roots available. ... collector for the Gen0 and Gen1 heaps and a mark/sweep/compact collector for ... heap or compacts free space out of the heap. ... the reference from the variable to the object in the heap. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: C++ Garbage Collector on VMS?
    ... case of a reference counting system, have a non-zero reference count) as ... to the beginning of the heap, updating the pointers to the objects as it ... (segregating allocation areas by type/size can help a lot there, ... any way with GC-controlled memory). ...
    (comp.os.vms)
  • Re: Help wanted - problems with heap
    ... Memory pressure, because of limited heap size. ... Any pointers as to work out what is happening would be welcome. ... interface expects to own that object from then on and delete it at its ...
    (rec.games.roguelike.development)
  • Re: HOW IS Memory Used by a VB App
    ... OK, I think the scene has been said for Virtual Memory, and other posts have ... variables contained an object reference then the body of the object would ... The heap manager takes care of ... if those pages get re-used by the heap manager then ...
    (microsoft.public.vb.general.discussion)
  • Re: Garbage collectable pinned arrays!
    ... reference to it anywhere on the call stack. ... But collecting the object and ... When the array is pinned it is copied to heap. ...
    (microsoft.public.dotnet.languages.csharp)