Re: Is There a Way to Remove a Module From Memory"



As with all Windows processes, the compiled code in an exe/dll/ocx is
"mapped" into virtual memory. In other words, pages of the process virtual
address space are pointed at areas in the relevant file, and the code is
paged in (via the VMM) as it's used. These virtual pages are set up as soon
as an exe is launched, but for a dll/ocx it occurs only when that component
is first accessed. This means that the exe is always part of your virtual
address space, but not all of it resides in RAM (physical memory) at any
given time. It also means that a dll/ocx may not even be in your virtual
address space. Once dll/ocx components are loaded, the VB runtime may decide
to unload them from your virtual memory if they're no longer being accessed.
The Project property 'Retain in Memory' overrides this, and is very
important in multi-threaded projects.

As for classes, the primary memory for class variables and Static variables
in the classes methods, are allocated as a single aggregate chunk from the
heap, for each instance of the object that's instantiated. Secondary memory
(i.e. for variable-length strings, arrays and referenced objects) are
allocated separately from the heap. All of this memory is returned to the
heap when the associated object is destroyed. This isn't the same as being
unloaded from either physical or virtual memory though. It simply means the
heap manager then has control over that virtual memory, and can decide to
reuse it later. Modern heap managers also try to decommit significant areas
of contiguous virtual memory in their free zones because it's more efficient
to reuse it as "demand zero" pages rather than risk paging in all the old
data debris from their last usage.

As for Modules, I believe that their primary memory (i.e. excluding
String-values/Array-values/referenced-objects) is allocated as a single
aggregate when the relevant component (exe/dll/ocx) is first initialised,
and separately for each thread on which it's initialised. Hence, if a
Standard EXE starts up then the total aggregate of primary data for the
variables in its Modules (and Static data in Module procedures) is allocated
at that time. The same happens for a dll/ocx when it is first accessed. For
a multi-threaded ActiveX exe, that aggregate is allocated separately for
each of its apartments/threads as they initialise. For a dll in a
multi-threaded environment (e.g. ASP), the aggregate is allocated separately
as each apartment accesses the dll

Tony Proctor

"Steve Gerrard" <mynamehere@xxxxxxxxxxx> wrote in message
news:w_idnZKqycL3o_7bnZ2dnUVZ_uqvnZ2d@xxxxxxxxxxxxxx

"Larry Serflaten" <serflaten@xxxxxxxxxxxxxx> wrote in message
news:e5cbSVipHHA.5008@xxxxxxxxxxxxxxxxxxxxxxx


Trying to find relavent material is getting harder and harder due to
everything
switching over to .Net, but there is this:

http://msdn2.microsoft.com/en-us/library/253b8k2c(VS.80).aspx
Like the rest of a program's code, DLL code is mapped into the address
space
of the process when the process starts up and it is loaded into memory
only
when needed. As a result, the PRELOAD and LOADONCALL code attributes
used
by .def files to control loading in previous versions of Windows no
longer
have meaning.

As it says, "Like the rest of a program's code..." which would mean the
entire
program's modules are loaded on demand.


I think "loaded on demand" is here referring to a machine code module,
i.e. an
executable or a dll, not a breakdown of the contents by original source
code
.bas module. Also, I think the "like the rest of a program's code", i.e.
the
executable, applies to the "mapped into the address space of the process"
part,
but not the "loaded into memory when needed" - since it is needed right
away, if
the executable is going to start.



That is not how I understood it. How would VB support compile on demand
if
the whole program had to be loaded when it started up?

http://msdn2.microsoft.com/en-us/library/aa241763(VS.60).aspx
The default in Visual Basic is to compile code on demand. This means
that
there
may be code in your component which is not compiled until the client
calls it.


Compile on demand, and the rest of the above link, is about what happens
when
debugging in the IDE. It does not apply to compiled executables and dlls.


AHA! I found the page I had seen before:
http://msdn2.microsoft.com/en-us/library/aa716325(VS.60).aspx
Visual Basic loads modules on demand - that is, it loads a module into
memory
only when
your code calls one of the procedures in that module. If you never call
a
procedure in a
particular module, Visual Basic never loads that module. Placing related
procedures in the
same module causes Visual Basic to load modules only as needed.



Again, "particular module", in my opinion, is referring to a .dll, not a
source
code .bas module. I simply can't imagine there would be any mechanism
included
in non-debug compiled .exes and .dlls, for separately loading code by
source
code .bas module.






.



Relevant Pages

  • Re: [Lit.] Buffer overruns
    ... > floating point support or a memory expansion option. ... had virtual memory support grafted on. ... > where the modified instruction was fetched from. ... vis-a-vis the official coporate strategic operating system TSS/360. ...
    (sci.crypt)
  • Re: scf /scannow & INFO in Event Viewer
    ... I know all about restore to ... pagefile to a low end of 2, ... The memory used by the user's ... Virtual Memory: Total paging file size for all drives is 2046MB ...
    (microsoft.public.windowsxp.general)
  • Re: virtual memory
    ... you can have virtual memory ... that software transparent swapping requires virtual memory. ... (since swapping it into physical memory is all or nothing). ...
    (comp.arch.embedded)
  • Re: Do I need a Page File?
    ... Intel designes the virtual memory. ... >> unlimited amounts of RAM, we wouldn't even NEED a paging file. ...
    (microsoft.public.windowsxp.general)
  • Re: Print statement within If-Then block changes output!!!????
    ... assembler/compiler into producing it. ... ordinary variable because all of them are BCD floating point. ... POKE a value into memory, ... It sounds like they're supposed to compile. ...
    (comp.lang.fortran)

Loading