Re: HOW IS Memory Used by a VB App
- From: "Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 19 Mar 2009 16:02:24 -0000
EXE's made with VB6 are loaded entirely at startup, not in parts.
The EXE is actually loaded on demand, via the paging system. At startup,
page table entries are created pointing to the corresponding areas of the
"backing file" (i.e. the EXE or DLL file). As the code executes, those pages
are automatically pulled into physical memory from the backing file.
If the same DLL is used in more than one program then this paging-in of the
code occurs in both processes. However, the backing file is the same and the
physical pages are the same. This then means less memory consumption, and
there's more chance of those pages being in physical memory because there's
twice the demand for them.
Tony Proctor
"Nobody" <nobody@xxxxxxxxxx> wrote in message
news:%23t4lr2JqJHA.3380@xxxxxxxxxxxxxxxxxxxxxxx
"David" <dw85745NOT@xxxxxxxxxxxxx> wrote in message
news:%23Y$z0jLpJHA.1292@xxxxxxxxxxxxxxxxxxxxxxx
How is memory used by a compiled VB application?
For example:
1) Is the entire program (Forms, Module, Classes, DLL;s loaded into
memory
when the application is initially started? -- OR -
2) Is just the StartUp Form, Modules, and Classes loaded into memory and
all other dependent forms and DLL's loaded dynamically from disk when
needed and released when not (object = Nothing) ? --OR --
3) What happens?
EXE's made with VB6 are loaded entirely at startup, not in parts.
EXE/DLL's generally can be segmented into parts called sections. In C++,
you
have control over how the code and data are segmented. For instance, a C++
developer can make a DLL or OCX that manipulate graphics and splits the
code
into two code sections, one for 2D, and the other for 3D graphics, so not
all the code is loaded at once. They do this through "#pragma" directives.
In VB6 we don't have this luxury. VB6 puts everything in 3 sections, one
for
static data(Global variables), one for code(all the code for
modules/classes/forms, etc.), and the last section for resources. You can
verify that with programs that view the EXE header. I have tested this
with
2 EXE's, one that doesn't have any forms, just one module with Sub Main(),
16 KB EXE size, and the other EXE has 30 forms, modules, classes, and one
user control, it's 1.2 MB in size. Both use 3 segments, so all the code is
loaded at once into memory at startup. Here is the software I used:
http://www.cgsoftlabs.ro/studpe.html
As for dynamic strings or arrays, I think VB6 uses
SysAllocString/SafeArrayCreate. VB6 and many other languages have their
own
memory managers. The runtime pre-allocates some memory at startup and use
it, when more memory is needed, it just allocates "larger" blocks than
what
you requested and use them. When you free memory, it just mark them as
free
but may not return it to the system. It assumes that you are going to need
it again soon, so the memory is not actually returned to the OS. Some
memory
managers actually free the memory when the application is minimized. I
noticed that VB6 does that on XP at least, not sure about other OS'es.
SysAllocString/SysFreeString is implemented in oleaut32.dll, which is part
of VB6 runtime and comes with some OS'es, so how strings are freed is
managed by that DLL or associated DLL's.
VB6 may be using heap functions in Windows for its own memory management
as
explained above, but I am not sure. See HeapSize() and related functions.
While VB6 doesn't have "Free" statement for strings, other than assigning
empty strings, it does have Erase statement, but it's for arrays. Try
putting the long string in a resource using "VB 6 Resource Editor" Add-in,
and load it into a string var, or in array var of String, and use Erase
statement. I have not tested this, so I don't know if there is a
difference.
.
- References:
- HOW IS Memory Used by a VB App
- From: David
- Re: HOW IS Memory Used by a VB App
- From: Nobody
- HOW IS Memory Used by a VB App
- Prev by Date: Re: WithEvents q
- Next by Date: Re: HOW IS Memory Used by a VB App
- Previous by thread: Re: HOW IS Memory Used by a VB App
- Next by thread: http request
- Index(es):
Relevant Pages
|